python基础一之while循环随机猜数字

Posted on 2019-01-19 16:31  mamba_T  阅读(573)  评论(0)    收藏  举报
 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")