预设一个数字,让用户来猜(0-9)
number=eval(input("let's guess a number:"))
prnum=8
N=0
while 0<=number<10:
N=N+1
if number==prnum:
print('bengio,{}'.format(N))
break
elif number<prnum:
number=eval(input("small!try it again:"))
elif number>prnum:
number=eval(input("big!,try it again:"))
随机参数一个数字,让用户来猜(0-100)
from random import*
number=eval(input("let's guess a number(0-100):"))
prnum=randint(0,100)
N=0
while 0<=number<100:
N=N+1
if number==prnum:
print('bengio,{}'.format(N))
break
elif number<prnum:
number=eval(input("small!try it again:"))
elif number>prnum:
number=eval(input("big!,try it again:"))