成品直播源码推荐,猜数字小游戏
#!/usr/bin/python3
'''
-*- coding: utf-8 -*-
@Author : Qixi
@Time : 2022/1/27 15:52
@Software: PyCharm
@File : guessingGame.py
'''
# guessing_game
from random import randint
from IPython.display import clear_output
guessRight = False
number = randint(0, 100)
guessTimes = 0 # 猜测次数
while not guessRight:
try:
ans = int(input("请输入你猜测的数字:")) # 接收用户输入的猜测
except ValueError:
print("请输入数字进行游戏")
else:
guessTimes += 1
clear_output()
if int(ans) == number:
print("恭喜您猜测正确,它就是{}!,截至游戏结束,你一共猜测{}次。".format(number,guessTimes))
break
elif int(ans) > number:
print("猜测数字过大")
elif int(ans) < number:
print("猜测数字过小")
以上就是 成品直播源码推荐,猜数字小游戏,更多内容欢迎关注之后的文章
标签:数字,int,number,猜测,小游戏,ans,直播,源码 From: https://www.cnblogs.com/yunbaomengnan/p/17571221.html