1, please use the code to achieve:
A. Using underscores to stitch each element of a list into a string, li= "Alexericrain"
B. Use underscores to stitch each element of the list into a string, li=[' Alex ', ' Eric ', ' Rain ' (optional)
Answer: String Join knowledge
li= "Alexericrain" v = "_". Join (LI) print (v)
Li = [' Alex ', ' Eric ', ' rain ']v = ' _ '. Join (LI) print (v)
2. Create Fun Template Program
Requirements: Waiting for the user to enter a name, place, hobby, according to the user's name and hobbies to carry out arbitrary reality
such as: Dear and amiable xxx, favorite in XXX place dry xxx
Answer: Tem.format
Name = input ("Please enter Name:") Addre = input ("Please enter Address:") Doing = input ("Please enter what to do:") tem = "Dear amiable {0}, favorite in {1}, local dry {2}" V = Tem.format (name, addre,doing) Print (v)
3, the production of random verification code, not case-sensitive.
Process:
--‐
User Execution Program
--‐
Show the user the verification code that needs to be entered
--‐
User-entered values
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:
For:
Def check_code (): import random Checkcode = "For me in Range" (4): Current = Random.randrange (0,4) If current! = I: temp = Chr (Random.randint (65,90)) else: temp = random.randint (0,9) Checkcode + = str ( Temp) return checkcodewhile True: code = check_code () print (code) v = input (">>>") v1 = v.upper () If v1 = = Code: print ("input correct") exit ()
4. Production form
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, the input is no longer entered and the user input is printed in a tabular format
A: Using format, index, and Expandtabs
s = "while True: v1 = input (" Enter user name: ") if V1 = =" Q "or V1 = =" Q ": break v2 = input (" Please enter password: ") v3 = INP UT ("Please enter email:") template = "{0}\t{1}\t{2}\n" v = Template.format (v1, v2, v3) s = s + vprint (S.expandtabs (20))
Python3 Basic Knowledge Quiz