if语句:
分支结构,选择结构
# Author:Huan
import getpass #引入密文密码
_username = 'Huan'
_password = 'abc'
username = input("name:")
#password = getpass.getpass("password:")
password = input("password:")
if _username == username and _password == password:
print("Welcome user {name} login...".format(name=username))
else:
print("Invaild username or password")
print(username,password)
while循环:
基于某种条件循环到结束。
# Author:Huan
age_of_huan = 26
count = 0
while count < 3:
guess_age = int(input("guess age:"))
if guess_age == age_of_huan:
print("yes,yo1u got it.")
break
elif guess_age > age_of_huan:
print("think smaller...")
else:
print("think bigger...")
count += 1
else:
print("you have tried too many times...")
for循环:
例1:
for i in range(0,10):
if i < 5:
print("loop",i)
else:
continue #跳出本次循环,进入下次循环
print("hello...")
例2:
# Author:Huan
age_of_huan = 26
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_huan:
print("yes,you got it.")
break
elif guess_age > age_of_huan:
print("think smaller...")
else:
print("think bigger...")
else:
print("you have tried too many times...")
continue:跳过循环的这一次循环,进行循环的下一次操作
break:停止整个循环