来玩猜数游戏吧

猜数游戏(1)

编写程序

'''
功能:猜数游戏(1)
作者:hf
日期:2021.11.20
'''

import random

target = random.randint(1, 100)

x = int(input("Try to guess the number I'm think of: "))

while True:
    if x > target:
        x = int(input('Too high! Guess again: '))
    elif x < target:
        x = int(input('Too low! Guess again: '))
    else:
        break

print("That's it! Thanks for playing.")

运行程序,查看结果
来玩猜数游戏吧_第1张图片

猜数游戏(2)

编写程序

'''
功能:猜数游戏
作者:hf
日期:2021.11.20
'''

import random

while True:
    target = random.randint(1, 100)

    x = int(input("Try to guess the number I'm think of: "))

    while True:
        if x > target:
            x = int(input('Too high! Guess again: '))
        elif x < target:
            x = int(input('Too low! Guess again: '))
        else:

运行程序,查看结果
来玩猜数游戏吧_第2张图片

你可能感兴趣的:(python)