# import random function from random import randint num=randint(0,100) min=0 max=100 cnt=0 while True: n=int(raw_input("input a number between %d %d: " %(min,max))) cnt+=1 if n<num: if min<n: min=n print "please try again,input a number between %d and %d: " %(min,max) continue elif n>num: if max>n: max=n print "please try again,input a number between %d and %d: " %(min,max) continue else: print '%d times! And the number is %d ' % (cnt,num) break |
python 简单的猜数字实现
最新推荐文章于 2023-09-24 23:46:22 发布