|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
i = 1
print ('Welcome to our game!')
temp = input ('Please input your number:')
guess = int (temp)
while guess != 8 and i<5:
if guess == 8:
print ('Correct! Congraturation')
else:
if guess < 8:
temp = input ('Your number is too small, please try again:')
guess = int (temp)
i=i+1
else:
temp = input ('Your number is too large, please try again:')
guess = int (temp)
i=i+1
print ('Game over')
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
============================= RESTART: D:\桌面文件\1.py ============================
Welcome to our game!
Please input your number:8
Game over
>>>
这个游戏的运算结果为什么不显示正确的结果,而是直接游戏结束?
本帖最后由 sunrise085 于 2020-8-29 10:41 编辑
因为你直接输入8,根本就进不了while循环
帮你修改了一下
- i = 1
- print ('Welcome to our game!')
- temp = input ('Please input your number:')
- guess = int (temp)
- while guess != 8 and i<5:
- if guess == 8:
- break#结果对了的话,就跳出循环
- else:
- if guess < 8:
- temp = input ('Your number is too small, please try again:')
- guess = int (temp)
- i=i+1
- else:
- temp = input ('Your number is too large, please try again:')
- guess = int (temp)
- i=i+1
- if guess == 8:#循环结束后,若结果对的话,就是print
- print ('Correct! Congraturation')
- print ('Game over')
复制代码
|
|