简介:利用随机函数生成0~999中的随机整数。当输入的数大于或者小于这个数,给出相应提示,猜对则结束!
import random
cmp = random.randint(0,999)
time = 1
small = 0
big = 999
answer = int(input("Input your answer(%d-%d): " %(small, big)))
while answer != cmp:
time += 1
if answer > cmp:
print("Your answer is big")
if answer > big:
big = big
else:
big = answer
answer = int(input("Input your answer(%d-%d): " %(small, big)))
else:
print("Your answer is small")
if answer < small:
small = small
else:
small = answer
answer = int(input("Input your answer(%d-%d): " %(small, big)))
print("The answer is %d. You get it by %d times" %(cmp, time))