Python-猜数小游戏案例

输入一个数,是否与系统所给的随机数吻合,并提示所猜数与系统所给的随机数对比大小,猜对结束,猜错继续:

 

代码如下:

import random
num = random.randint(1,10)
print('----------game--------')
temp = input("input a number")
guess = int(temp)
while guess != num:
    temp = input("is woring,one more time:")
    guess = int(temp)
    if guess == num:
        print("is rigth")
    else:
        if guess > num:
            print("is too big")
        else:
            print("is too small")
print("game over")

 

posted @ 2018-12-16 15:19  OneShit  阅读(1038)  评论(0编辑  收藏  举报