标签:mat if...else ## input invalid pre pytho lan 语法
3.1 if流程判断
3.1.1 if else流程判断
#!Author:lanhan
_username = ‘lanhan‘
_password = ‘123‘
username = input("username:")
password = input("password:")
if username == _username and password == _password:
print("welcome user {name} login...".format(name=username))
else:
print("Invalid username or password!")
3.1 .2if...elif...else流程判断
#!Author:lanhan
age_of_oldboy = 56
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes,you got it. ")
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger! :")
3.2 while流程判断
3.2.1while True
实例1:
#!Author:lanhan
count = 0
while True:
print("count:",count)
count = count +1
if count == 3:
break
实例2:
#!Author:lanhan
count = 0
age_of_oldboy = 56
while True:
if count == 3:
break
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes,you got it. ")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger! :")
count +=1
3.2.2while...else
示例1:
#!Author:lanhan
count = 0
age_of_oldboy = 56
while count < 3:
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes,you got it. ")
break #####不往下走了,直接跳出整个循环
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger! :")
count +=1
else:
print("you have tried too many times..fuck off")
3.3 for流程判断
3.3.1 for i in 变量
示例1:
#!Author:lanhan
for i in range(0,10,2):
if i < 3:
print("loop",i)
else :
continue ####跳出本次循环,继续下次循环
print("hehe.....")
3.3.2for...else
示例1:
#!Author:lanhan
count = 0
age_of_oldboy = 56
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes,you got it. ")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger! :")
else:
print("you have tried too many times..fuck off")
标签:mat if...else ## input invalid pre pytho lan 语法
原文地址:http://www.cnblogs.com/decorator/p/7898767.html