(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)