About the Python loop

Source: Internet
Author: User

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

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.