简体   繁体   English

有人可以告诉我我的代码有什么问题吗?

[英]Could someone tell me what the problem is with my code?

I've just started learning and have just finished this code if you get 2 answers wrong, your third answer will be wrong even if it's the right number: Here's my code:我刚刚开始学习并且刚刚完成此代码,如果您有 2 个答案错误,您的第三个答案将是错误的,即使它是正确的数字:这是我的代码:

secretnum = 9
maxguess = 2
guesscount = 0
guess = int(input('Guess: '))

while guesscount < maxguess:

    if guess == secretnum:
        guesscount = 5
        print('Well done')

    else:
        print('Try Again')
        guesscount += 1
        guess = int(input('Guess: '))
        if guesscount == maxguess:
            print('You Lost!')

What's wrong with it?它出什么问题了? Here's a pic of what it looks like这是它的样子

secretnum = 9
maxguess = 3
guesscount = 0
guess = int(input('Guess: '))

while guesscount < maxguess:
    guesscount += 1
    if guesscount == maxguess:
        print('You Lost!')
        break
    if guess == secretnum:
        print('Well done')
        break

    else:
        print('Try Again')
        guess = int(input('Guess: '))

secret = 9
guesses = 0
max_guesses = 3
while guesses < max_guesses:
    try:
        guess = int(input('Guess: '))
    except ValueError:
        print("Enter a Number!")
        continue
    if guess == secret:
        print("Well done!")
        break
    guesses += 1
if guesses >= max_guesses:
    print("You lost")

Here it is:这里是:

secretnum = 9
maxguess = 3
guesscount = 0

while guesscount < maxguess:
    guess = int(input('Guess: '))
    if guess == secretnum:
        print('Well done')
        break
    else:
        print('Try Again')
        guesscount += 1

if guesscount == maxguess:
    print("You lost")

Python deals with formatting... Python 处理格式化...

So you should indent your code, because that is the way python is going to get every block of code所以你应该缩进你的代码,因为这是 python 获取每个代码块的方式

Check out this image看看这张图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人能告诉我我的代码有什么问题吗 - Can someone tell me what is wrong with my code 有人可以告诉我我的 animation 代码有什么问题吗? - Can someone tell me what's wrong with my animation code? 有人能告诉我这里发生了什么吗 - Could someone tell me what is going on here 有人能告诉我这段代码有什么错误吗? - Can someone tell me what are the mistakes in this code? 我的代码指出我的列表在第 9 行超出范围。有人可以告诉我如何解决吗? - My code points that my list is out of range on line 9. Could someone tell me how to fix it? 您能告诉我代码有什么问题吗? - Could you tell me what's wrong with my code? 有人可以告诉我为什么此代码无法按预期工作吗? - could someone tell me why this code is not working as expected? 有人可以告诉我我的代码有什么问题吗? 我在调试时遇到问题 - Can someone tell me what is wrong with my code? I am having problems debugging python 中的变量不起作用,有人可以告诉我我的代码有什么问题吗? - Variable in python not working, can someone tell me what is wrong with my code? 有人可以检查我的代码并帮助我解决问题吗? 错误 =“列表索引超出范围” - Could someone check my code and help me out with a problem? Error = "list index out of range"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM