while循环初探
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了while循环初探相关的知识,希望对你有一定的参考价值。
1 count = 0 2 #while True: 3 while count < 3: 4 count +=1 #count每次加1 5 guess_number = int(22) 6 get_number = int(input(‘Please enter the number you guessed>>>‘)) 7 8 if guess_number == get_number: 9 print("Congratulations, you guessed it") 10 exit() 11 elif guess_number > get_number: 12 print("The number you guessed is too small") 13 else: 14 print("The number you guessed is too big") 15 else: 16 print(‘too many times‘) #上面条件不满足的时候打印
#while 更改版超过三次询问是否继续游戏
1 count = 0 2 while True: 3 guess_number = int(22) 4 get_number = int(input(‘Please enter the number you guessed>>>‘)) 5 6 if guess_number == get_number: 7 print("Congratulations, you guessed it") 8 exit() 9 elif guess_number > get_number: 10 print("The number you guessed is too small") 11 else: 12 print("The number you guessed is too big") 13 count += 1 14 if count == 3: 15 a = input("You guessed it three times.Do you want to continue playing this game?[N/Y]") 16 if a == ‘n‘: 17 print(‘That is a pity!!‘) 18 exit() 19 else: 20 count = 0 21 continue
以上是关于while循环初探的主要内容,如果未能解决你的问题,请参考以下文章