猜数字游戏 python

1.运行结果

猜数字游戏 python_第1张图片

2. 源代码如下

import random
n = random.randint(0, 9)
count = 0
print(n)
s = int(input("please enter a number!: \n"))
while True:
    if 0 <= s <= 9 and s != n:
        if s > n:
            count += 1
            print("is bigger")
        else:
            count += 1
            print("is smaller")
        s = int(input("please enter a number!: \n"))
    elif s == n:
        count += 1
        print(f"ok enter_times : {count}")
        break
    else:
        print("enter error!")
        s = int(input("please enter a number!: \n"))

 

你可能感兴趣的:(python,游戏,开发语言)