python -- 流程判断 & 循环loop
流程判断 if-elif-else 那些事
if-else
name,passwd = 'Gao',"abc123"
user_name = input("User Name is : \n")
user_password = input("User Password is : \n")
if name == user_name and passwd == user_password:
print("Welcome {0} login...".format(user_name))
else:
print("Invail username or password...")
if-elif-else
old_boy_age = "40"
guess_age = input("Guess age is : \n")
if guess_age == old_boy_age:
print("Bingo")
elif guess_age > old_boy_age:
print("Higher! Guess lower")
else:
print("Lower! Guess higher")
循环loop
while
一个简单的while,死循环。
count = 0
while True:
count += 1
print(count)
带break的while
count = 0
while True:
print("Count:", count)
count += 1
if count > 100:
break
不带计数器的while
old_boy_age = "40"
while True:
guess_age = input("Guess age is : \n")