1 Star 0 Fork 0

wdc/Python001

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Guessing_Game.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
import random
a = comGuess = random.randint(0, 100) # a and comGuess is initialised with a random number between 0 and 100
while True: # loop will run until encountered with the break statement(user enters the right answer)
userGuess = int(input("Enter your guessed no. b/w 0-100:")) # user input for guessing the number
if userGuess < comGuess: # if number guessed by user is lesser than the random number than the user is told to guess higher and the random number comGuess is changed to a new random number between a and 100
print("Guess Higher")
comGuess = random.randint(a, 100)
a += 1
elif userGuess > comGuess: # if number guessed by user is greater than the random number than the user is told to guess lower and the random number comGuess is changed to a new random number between 0 and a
print("Guess Lower")
comGuess = random.randint(0, a)
a += 1
else: # if guessed correctly the loop will break and the player will win
print("Guessed Corectly")
break
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ijiwei/Python001.git
git@gitee.com:ijiwei/Python001.git
ijiwei
Python001
Python001
master

搜索帮助