# 需求:猜年齡,可讓用戶最多猜三次 age = 60 for i in range(3): guess = int(input("Input Age: ")) if guess > age: print("Too bigger.") elif guess < age: print("Too smaller.") else: print("You got it!") break if i+1 is 3: print("3 times lost.")
# 需求:猜年齡,每隔三次,問他一下還想不想再玩。 import sys age = 60 i = 0 while True: i += 1 guess = int(input("Input Age: ")) if guess > age: print("Too bigger.") elif guess < age: print("Too smaller.") else: print("You got it!") break if i%3 is 0: flag = input("Go on. Yes or No? ") if flag.upper() == "YES": pass elif flag.upper() == "NO": break
# 編寫登錄接口: # 輸入用戶名密碼 # 認證成功後顯示歡迎信息 # 輸錯三次後鎖定 # 重點是 *鎖定* import getpass f = open("lock_user.txt", "r+") lock = f.read().strip() #So important i = 1 while True: username = input("Input your username: ") if username == lock: print("The username is locked.") break else: password = getpass.getpass("Input your password: ") if username == 'liukai' and password == 'liukai123': print('Welcome!') break else: print('Error.') i += 1 if i == 4: f.write(username + "\n") break f.close()