Doubt on "continue" (Syntaxerror: 'continue' not properly in loop)

Asked

Viewed 317 times

0

I’m starting in python and I can’t figure out why the error below, could help me?

def SecretNumber():
    GotIt = False
    while GotIt == False:
        One = int(input("Type a number between 1 and 10: "))
        Two = int(input("Type another number between 1 and 10: "))

    if (One >= 1) and (One <= 10):
        if (Two >= 1) and (Two <= 10):
            print('Your secret number is: ' + str(One * Two))
            GotIt = True
            continue
        else:
            print('Incorrect second value!')
    else:
        print("Incorrect first value!")
    print("Try again!")

*****File "cell_name", line 14 Syntaxerror: 'continue' not properly in loop*****

  • Are you calling the continue out of a loop. The fact of its first if be recoilled less than the while makes it not belong to the logical block of the loop repetition and thus in the line using the continue, consequently, it will also be out of the loop - it is worth mentioning that in this way its loop of repetition is infinite because GotIt never ceases to be False.

  • That’s it Osvaldo, as Caio mentioned, the problem occurs because the continue works within a loop of repetition, is the python identifies the blocks of codes by identation, in your case your if stayed out of the block, while only 4 spaces in your complete if block and should work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.