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' or a == 'N':
17             print('That is a pity!!')
18             exit()
19         else:
20             count = 0
21             continue

 

posted @ 2017-09-30 15:26  橙子味的萝卜  阅读(178)  评论(0编辑  收藏  举报