# 导引随机数模块,随机产生数字
print("~~~~~~~~~~~~~~~~~~~~~~~~欢迎来到张氏游戏玩家~~~~~~~~~~~~~~~~~~~~~~~~")
print(" ")
import random
# 使用randint方法,产生0--100随机数
system_num = random.randint(0,100)
print("system_num is %s"%system_num)
# 进入选择结构,猜数字
while True:
user_num = int(input("请输入您要猜的数字(范围:0--100): "))
if user_num > system_num:
print("对不起,您猜大了")
elif user_num < system_num:
print("对不起,您才小了")
else:
print("恭喜您,猜对了!")
conform = input("请问,您需要继续猜吗?(Y/y)")
if conform != "Y" and conform != "y":
print("感谢您的使用,欢迎下次使用...")
break
else:
system_num = random.randint(0,100)
print("system_num is %s"%system_num)
Python 实战案例--猜数字游戏
最新推荐文章于 2022-04-15 22:36:56 发布