2021-11-18 猜数小游戏

文章目录

  • 一,猜数游戏
    • (1)编写程序
    • (2)运行程序,查看结果

一,猜数游戏

(1)编写程序

2021-11-18 猜数小游戏_第1张图片

import random

while True:

    target = random.randint(0, 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
    choice = input("That's it would you like to play again?(yes/no)")
    if choice == 'no':
        break
print("that's it! Thanks for playing.")

(2)运行程序,查看结果

2021-11-18 猜数小游戏_第2张图片

你可能感兴趣的:(python)