码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-01-19 17:27:45      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:NPU   break   random   input   python基础   sse   else   more   games   

 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循环随机猜数字

标签:NPU   break   random   input   python基础   sse   else   more   games   

原文地址:https://www.cnblogs.com/mamba-T/p/10292160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!