guess.py
age_of_oldboy = 56
count = 0
while True:
if count ==3:
break
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("You are right")
break
elif guess_age > age_of_oldboy :
print("think smaller...")
else:
print("think bigger!")
count +=1
#count +=1等同count = count + 1
+++++++++++++++++++++++++++++
guess 优化.py
age_of_oldboy = 56
count = 0
while count<3:
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("You are right")
break
elif guess_age > age_of_oldboy :
print("think smaller...")
else:
print("think bigger!")
count = count + 1
#if count == 3:
else:
print("You have tried too many times......fuck off")
#count +=1等同count = count + 1
++++++++++++++++++++++++++++
guess for.py
age_of_oldboy = 56
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy :
print("You are right")
break
elif guess_age > age_of_oldboy :
print("think smaller...")
else:
print("think bigger!")
#if count == 3:
else:
print("You have tried too many times......fuck off")
#count +=1等同count = count + 1
+++++++++++++++++++++++++++++++++
info3 ='''
------------- info of {0}----------
Name:={0}
Age:={1}
Job:={2}
Salary:={3}
''' .format(name,Age,Job,Salary)
print(info3)
#print (info)
+++++++++
login.py
_username = "a"
_passwd ="123"
username = input("username:")
passwd = input("passwd:")
print(username,passwd)
if _username == username and _passwd == passwd:
print("Welcome user {name} login.....".format(name= username)) #强制缩进,省去结束符
else:
print("Invalid username or password!")
+++++++++++++++++++++++
passwd.py
import getpass #导入getpass
_username = "a"
_passwd ="123"
username = input("username:")
#passwd = getpass.getpass("passwd:") #getpass密文密码
passwd = input("passwd:")
print(username,passwd)
if _username == username and _passwd == passwd:
print("Welcome user {name} login.....".format(name= username)) #强制缩进,省去结束符
else:
print("Invalid username or password!")
++++++++++++++++++++++++++++++++++++
vav2.py
print("Hello World!")
name = "Cedar Li"
print("my name is",name)
name2 = name
msg = "what's your name?"
'''
name = "PaoChe Ge"
print(name,name2)
gf_of_oldboy = "Chen rong hua"
GFOfOldboy ="chen rong hua"
'''
print("what",msg)
+++++++++++++
while.py
'''count = 0
while True:
print("count:",count)
count = count + 1 #count+ =1
if count == 1000:
break
#break 中止运行
'''
for i in range(0,10,3):
print("loop:",i)
++++++++++++++
while continue.py
'''
for i in range(0,10):
if i < 3:
print("loop:",i)
else:
continue #continue跳出本次循环,继续下次循环;break是结束整个循环,所以I>3之后,后面就不执行。
print("hehe.......")
'''
for i in range(10):
print("__________",i)
for j in range(10):
print(j)
if j >5:
break #break结束当前循环,也就是for这个循环。
++++++++++++++++++++
登录3次锁定
username = "abc"
passwd = "123"
count = 0
while count <3:
_username = input("username:")
_passwd = input("passwd:")
if username == _username and passwd == _passwd:
print("Welcome {name} login......".format(name=_username))
break
else:
print("{name} are wrong,You are wrong number {number},Please try agee!".format(name=_username,number=count+1))
count +=1
if count ==3:
print("You are wrong {number} ,Please try atry".format(number=count))