This article is mainly for you to introduce the Python learning function and process control, with a certain reference value, interested in small partners can refer to
#猜年龄大小, users guess up to three times
Age = i = 0 when I < 3: guess_age = int (input ("Please input your answer:")) if Guess_age > Age: prin T ("Too Big...try Again") Elif Guess_age < age: print ("Too small...try Again") else: Print ("you guessed it!") Break i + = 1 if i = = 3:
#猜年龄, ask if you want to play every three times
Age = $ for I in range (1,100): guess_age = int (input ("Your answer:")) if Guess_age > Age: pri NT ("Too Big...try Again") Elif Guess_age < age: print ("Too small...try Again") else: Print ("You guessed it!") If i%3 = = 0: choice = input ("Would like play again?") Yes or no ") if choice = =" Yes ": continue if choice = =" No ": Break Else: continue
#登录验证, input error three times lock user
f = open (' C:/user_passwd.txt ', ' r ') j = 3 System_user_name = str (f.readline ()) system_passwd = str (f.readline ()) F.close () For I in range (1,5): user_name = str (input ("Your UserID:")) password = str (input ("passwd:")) if i = = 3: s = open (' C:/user_passwd.txt ', ' r+ ') s.write ("\nlocked") s.close () print ("This user is locked!") break Else: if user_name + ' \ n ' = = system_user_name and Password = = system_passwd: print ("Welcome" + US Er_name + ' \ n ' + "has a good time!") Break Else: J-= 1 i + = 1
Print ("UserID or password is wrong,please try once again and you have" + \ Str (j) + ' Times choice ')