猜随机数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import random
times = shuzi = 3 #尝试次数
suiji = random.randint(1,10) #随机数范围
while times!= 0:
if times==shuzi: #第一次的问句
tmp=input('Please enter a number:')
else:
tmp=input('Please enter again:')#接下来的问句
while not tmp.isdigit() :
tmp=input('Enter a \'number\' again:')#没有输入数字的问句
num=int(tmp)
if num==suiji:
print ('Yes\nend') #猜对了
times = times-times
else :
times= times -1 #次数-1
if times==0:
print('Try too much\nthe answer is' ,suiji,'\nend') #试太多次了,告诉答案
else:
if num>suiji:
print('too big') #大了
else:
print('too small') #小了

猜随机数
https://2333.world/_posts/2020_02_12/猜随机数/
作者
Yuban10703
发布于
2020年2月12日
许可协议