一,猜数游戏
(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)运行程序,查看结果

本文介绍了一个简单的猜数游戏实现过程,使用Python语言通过随机模块生成一个0到100之间的整数,玩家需要通过提示逐步猜测正确的数字。游戏提供反馈以帮助玩家调整猜测,并在猜中后询问是否继续游戏。
1744

被折叠的 条评论
为什么被折叠?



