Python core programming version 2, chapter 6, chapter 6 Exercise Part 5-answers to Python core programming-self-developed-

Source: Internet
Author: User

(B) Code . Another method is to search in reverse order:
def rfindchr (string, char ):
A = string
Index =-1
K = Len (a)
for I in a [:-1]:
K = k-1
If I = CHAR:
Index = k
Print Index
Break
If Index =-1: Print 'index = ', index
A = raw_input ('Please input a string... ')
B = raw_input ('Please input a character to be find in this string... ')
rfindchr (a, B)

(c) code:
def subchr (string, origchar, newchar):
output = ''
for I in origchar:
If I = string:
output = output + newchar
else:
output = output + I
Print Output
subchr ('C', 'abccddfasdfddacda', 'k ')

6-13.
The string. String module contains three functions: atoi (), atol (), and atof (). They are responsible for converting strings into integer, long integer, and floating point numbers respectively. From Python 1.5 onwards, Python's built-in functions int (), long (), float () can also do the same thing. In this article, complex () functions can convert strings to the plural (however, before 1.5, these conversion functions can only work on numbers) from the blog.
The string module does not implement an ATOC () function, so you can implement an ATOC () and accept a single string for parameter input, a string that represents the plural number, for example, '-1.23e + 4-5.67j', returns the corresponding plural object. You cannot use eval () functions, but you can use complex () functions, and you can only use: complex (): complex (Real, IMAG) with the following restrictions) both real and imag must be floating point values.
[Answer]
The Code is as follows:
Def ATOC (input ):
Print complex (input). Real
Print complex (input). imag

Input = raw_input ('Please input a complex number ...')
ATOC (input)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.