Please use code to implement:
A. Using underscores to stitch each element of a list into a string, Li = "Alexericrain"
test="alexericrain"v='_'. Join (Test) Print (v)
Operation Result:
A_l_e_x_e_r_i_c_r_a_i_n
B. Use an underscore to stitch each element of the list into a string, Li = [' Alex ', ' Eric ', ' Rain '] (optional)
test=['Alex','Eric','rain' ]v='_'. Join (['Alex',' Eric 'rain'])print(v)
Operation Result:
Alex_eric_rain
Implement an integer addition calculator:
Such as:
Content=input (' Please enter content: ') # such as: 5+9 or 5+9 or 5+9
Test=input (" Please enter \ n") v1,v2=test.split ('+') v1 =Int (v1) v2=Int (v2) v3=v1+v2print(v3)
How many decimal decimals are there in the user input for statistical calculation? A few letters?
such as: Content=input (' Please enter content: ') # such as: asduiaf878123jkjsfd-213928
Answer:
Content=input ("Please enter content \ n") I=0j=0 forNameinchCONTENT:TP=Name.isalpha () ifTP = =false:i+=1Else: J+=1Print(" number is", i)Print("string is", j)
Create Fun template Programs
Requirements: Waiting for the user to enter a name, place, hobby, according to the user's name and hobbies to carry out arbitrary reality
Name=input (" Please enter name \ n") address=input (" Please enter address \ n" ) like =input (" Please enter hobby \ n") Test="{0} likes in {1}{2} "new_test=Test.format (name,address,like)print(new_test)
Make random verification codes that are not case sensitive.
Process:
-User Execution Program
-Show the user the verification code that needs to be entered
-Values entered by the user
The value entered by the user and the displayed value are the same as the actual correct information; otherwise continue to generate random verification code continue to wait for user input
Example of generating a random CAPTCHA code:
defCheck_code ():ImportRandom Checkcode="' forIinchRange (4): current=random.randrange (0,4) ifCurrent! =i:temp=CHR (Random.randrange (65,90)) Else: Temp=random.randrange (0,9) Checkcode+=Str (temp)returnCheckcodecode=Check_code ()Print(Code) whileTrue:code=Check_code ()Print(code) name=input ("Please input\n") ifName! =Code:Print("Input Error") Else: Print("Input Success") Break
Operation Result:
Xn2r
Please input
NG
Input error
Igdp
Please input
Igdp
Input success
Develop a sensitive word filter that prompts the user to enter content if the user enters content that contains special characters: such as "Ms. Cang" and "Tokyo Hot", replace the content with * * *
M1=str.maketrans ("Ms. Cang","***") M2=str.maketrans ("Tokyo Hot","***") Search=input ("Please enter the content you want to search \ n")ifSearch = ="Ms. Cang": New_search=Search.translate (M1)Print(New_search)elifSearch = ="Tokyo Hot": New_search=search.translate (m2)Print(New_search)Else: Print("the content you search for is", search)
Make a table
Loop Prompt user input: User name, password, mailbox (requires the user to enter a length of not more than 20 characters, if more than the first 20 characters are valid)
If the user enters Q or Q for no further input, the user input is printed in tabular form
whileTrue:name= Input ("Please input your name\n") ifName = ="Q" orName = ="Q": Print("is exiting") Break Else: Print("please continue to enter") passwd= Input ("Please input your password\n") Email= Input ("Please input your e-mail\n") New_name= Name.expandtabs (20) new_passwd= Passwd.expandtabs (20) New_email= Email.expandtabs (20)Print(New_name,new_passwd,new_email)
Python string Exercises