|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 dwjjun 于 2021-8-4 11:37 编辑
- import random
- def loop():
- scc_ret = random.randint(1, 10)
- print(scc_ret)
- times = 3
- guess = 0
- while guess != scc_ret and times > 0:
- print(f"你还有{times}次机会,", end="")
- times = times - 1
- temp = input("请输入1-10的整数:")
- if len(temp) == 0:
- print("你什么也没有输入!")
- elif temp.isdigit() is False:
- print(f"你输入的是 ”{temp}“ 不是数字.")
- else:
- guess = int(temp)
- if guess == scc_ret:
- print(f"你输入的是 ”{temp}“ ")
- print(f"恭喜你猜对了.我隐藏的数字是 “{guess}” ^_^")
- break
- else:
- if guess < scc_ret:
- print(f"你输入的是 ”{guess}“ 猜小了")
- else:
- print(f"你输入的是 ”{guess}“ 猜大了")
- if times == 0:
- print("你的机会用光了.")
- new_loop()
- def new_loop():
- print("是否重新开始?yes,y重新开始。no或n游戏结束。")
- r = input("请输入:")
- if r == "yes" or r == "y":
- loop()
- if r == "n" or r == "no":
- print("游戏结束")
- if __name__ == '__main__':
- print("猜猜我隐藏的数字是多少?")
- loop()
复制代码 |
|