Python中for循环和while循环、if判断
1、while循环
案列:while循环和if判断以及while和else使用
man_age = 56
count = 0
while count < 3:
manson_age = int(input("age= "))
if manson_age == man_age:
print ("Guess It")
break
elif manson_age > man_age:
print ("Guess Big")
else:
print ("Guess Small")
count += 1
else:
print("Try too many times... Fuck off!")
2、if判断
案列:
_user = "manson"
_passwd = "123"
username = input("username: ")
password = input ("passwor: ")
if username == _user and password == _passwd:
print("Welcom user {name} login".format(name=_user))
else:
print ("login fail")
案列:学习多个条件判断
man_age = 56
manson_age = int(input("age= "))
if manson_age == man_age:
print ("Guess It")
elif manson_age > man_age:
print ("Guess Big")
else:
print ("Guess Small")
3、for循环
#Author: Manson Cui
count = 23
for i in range(3):
age = int(input("age: "))
if age == count:
print ("Guess It")
break
elif age > count:
print ("Guess Big")
else:
print ("Guess small")
else:
print("Try too many times... Fuck off!")
大家一起来学习