在高低游戏中获得正确输出时遇到问题

问题描述 投票:0回答:1

我必须确保让玩家知道他们的猜测是否太低、太高或正确,但在询问他们的界限后我没有得到任何输出。有什么帮助指出我做错了什么吗?我相信这是我当前版本的Python。

print('Welcome to the Higher or Lower game!')
import random
lowr = int(input('What would you like for your lower bound to be?: '))
upr = int(input('And your highest?: '))
x = (random.randint(lowr, upr))
if lowr >= upr:
    print('The lowest bound must not be higher than highest bound. Try again.')
    if lowr < upr:
        g = int(input('Great now guess a number between', lowr, 'and', upr, ':'))
    while g > x:
        int(input('Nope. Too high, Guess another number: '))
        while g < x:
            int(input('Nope. Too high, Guess another number: '))
            if g == x:
                print('You got it!')
python loops
1个回答
0
投票

这是正确代码的可能版本:

import random
print('Welcome to the Higher or Lower game!')
while True:
    lowr = int(input('\nWhat would you like for your lower bound to be?: '))
    upr = int(input('And your highest?: '))
    x = (random.randint(lowr, upr))
    if lowr >= upr:
        print('The lowest bound must not be higher than highest bound. Try again.')
    if lowr < upr:
        g = int(input(f"""Great now guess a number between
            {lowr} and {upr}:"""))
        while True:
            if g < x:
                g = int(input('Nope. Too low, Guess another number: '))
            elif g > x:
                g = int(input('Nope. Too high, Guess another number: '))
            if g == x:
                print('You got it!')
                break

存在一些错误:输入法和事件 lagestine 的使用。

© www.soinside.com 2019 - 2024. All rights reserved.