python基础一之while循环随机猜数字
Posted mamba-t
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python基础一之while循环随机猜数字相关的知识,希望对你有一定的参考价值。
1 # Author:"Mamba" 2 3 import random 4 setNum = random.randint(1,10) 5 #print(setNum) 6 count = 0 7 while count == 0: 8 print(‘let`us play guess number games‘) 9 print(‘your have three times ,now begin‘) 10 guess = int(input("please input your number:")) 11 if guess == setNum: 12 print("great ,so clever you are") 13 break 14 elif guess < setNum: 15 print(‘{0}{1}{2}{3}{4}‘.format(‘sorry,‘, ‘the number you guessed is small,‘, ‘and you have ‘, (2 - count), ‘ more chances.‘)) 16 else : 17 print(‘{0}{1}{2}{3}{4}‘.format(‘sorry,‘, ‘You guessed a big number,‘, ‘and you have ‘, (2 - count),‘ more chances.‘)) 18 count =count +1 19 break 20 while count < 3: 21 guess = int(input("please input your number again:")) 22 if guess == setNum: 23 print("great ,so clever you are") 24 break 25 elif guess < setNum: 26 print(‘{0}{1}{2}{3}{4}‘.format(‘sorry,‘, ‘the number you guessed is small,‘, ‘so you have ‘, (2 - count), ‘ more chances.‘)) 27 else : 28 print( ‘{0}{1}{2}{3}{4}‘.format(‘sorry,‘, ‘You guessed a big number,‘, ‘so you have ‘, (2 - count), ‘ more chances.‘)) 29 count =count +1 30 else : 31 print("you have tried too many times ,game over")
以上是关于python基础一之while循环随机猜数字的主要内容,如果未能解决你的问题,请参考以下文章