#/usr/bin/env python #getpass用法 import getpass _username = "test" _password = "passwd" username = getpass.getpass("your name is:") password = getpass.getpass("your passwd is:") print(username,password) if _username == username and _password == password: print("Welcome system of {name}" .format(name=username)) else: print("invalid username or password...") #猜年龄(while if else elif for) #example 1 age_of_test = 34 while True: guess_age = int(input("guess age:")) if guess_age == age_of_test: print("yes,you got it...") break elif guess_age > age_of_test: print("no,think smaller...") else: print("no,think bigger...") #example 2 age_of_test = 34 count = 0 while True: if count == 3: break guess_age = int(input("guess age:")) if guess_age == age_of_test: print("yes,you got it...") break elif guess_age > age_of_test: print("no,think smaller...") else: print("no,think bigger...") count +=1 #example 3 age_of_test = 34 count = 0 while count < 3: guess_age = int(input("guess age:")) if guess_age == age_of_test: print("yes,you got it...") break elif guess_age > age_of_test: print("no,think smaller...") else: print("no,think bigger...") count +=1 #写法1 #if count == 3: #写法2 else: print("you have tried too many times...") #example 4 age_of_test = 34 for i in range(3): guess_age = int(input("guess age:")) if guess_age == age_of_test: print("yes you got it...") break elif guess_age > age_of_test: print("no,think smaller...") else: print("no,think bigger...") else: print("you havd tried many times...") #example 5 count = 0 age_of_test = 34 while count < 3: guess_age=int(input("guess age:")) if age_of_test == guess_age: print("yes,you got it...") break elif guess_age > age_of_test: print("no,think smaller...") else: print("no,think bigger...") count +=1 if count == 3: continue_confirm = input("do you want to continue thinking... ") if continue_confirm != "n": count = 0