猜数游戏

题目如下:

timu

代码实现:
import random
def GuessNumber():
    guess = random.randint(0,100)
    i = 1
    print("检测一个0到100之间的整数。")
    print("第{0}次猜,请输入一个整形数字:".format(i))
    Num = int(input())
    while Num != guess:
        if Num < guess:
            print("太小!")
        else:
            print("太大")
        i += 1
        print("第{0}次猜,请输入一个整形数字:".format(i))
        Num = int(input())
    print("恭喜你终于猜对啦,这个数是:{}".format(guess))
结果展示:

jieguo

更多推荐