Loops are also referred to as traversal or iteration
There are two types of loops in Python: while and for loops
#如果账号密码错误, prompting the user to reenter the error message
#如果输入错误的次数超过3次, program exits automatically
#用户名输入空的话, you want to prompt the user name cannot be empty, the user name input empty also counted as failed once
#_ *_conding:utf-8_*_ Note: Define the encoding for Utf-8 common
# name= "Cuimeiping"
# password= "cui1234"
# for I in range (3):
# username=input ("Please enter user name:")
# userpassword=input ("Please enter password:")
# if Name==username and Password==userpassword:
# print ("Welcome Triping home!" ")
# break
# elif username== "" or userpassword== "":
# print ("The user name and password entered cannot be empty!") ")
# Else:
# print ("Please enter the correct user name or password")
# name= "Cuimeiping"
# password= "cui1234"
# count=1
# while Count<3:
# username=input ("Please enter user name:")
# userpassword=input ("Please enter password:")
# if username== "" or password== "":
# print ("User name password cannot be empty")
# elif Name!=username and Password!=userpassword:
# print ("Please enter the correct username and password!") ")
# count = Count + 1
# Else:
# print ("Welcome Home")
# break
#写一个注册的程序, enter USERNAME,PASSWD,CONFIRMPASSWD
#注册成功之后, prompt registration is successful, program exits, require user name cannot be duplicated
#错误次数也是3次
Name= "Cuimeiping"
Password= "cui1234"
Confirmpasswd= "cui1234"
Count=1
For I in range (3):
Username=input ("Please enter a user name:")
Userpassword=input ("Please enter a password:")
Userconfirmpasswd=input ("Please enter confirmation password")
If Username==name:
Print ("The user name you entered already exists, please re-enter")
Elif username== "" or userpassword== "" or confirmpasswd== "":
Print ("User name and password cannot be blank, please enter user name or password")
Else
Print ("Registration successful")
Break
About the Python loop