print SyntaxError: invalid syntax

1

Good morning!

I am currently learning Python and in a simple application of practice I found the following error:

File "ruta_fichero", line 9
    print(num2, "es menor que ", str(num1))
        ^
SyntaxError: invalid syntax

The code that I have written is the following:

num1 = int(input("Escribe un número: "))
num2 = int(input("Escribe un número mayor que ", str(num1), ":"))

while num2 > num1:
num1 = num2
num2 = int(input("Escribe un número mayor que ", str(num1), ":")


print(num2, "es menor que ", str(num1))

Do you know where the syntax error may be?

Thank you very much!

    
asked by Jesús Furió 15.10.2018 в 23:33
source

1 answer

1

Many times the point where you mark the error is not where it is, but where it is detected.

num2 = int(input("Escribe un número mayor que ", str(num1), ":")
print(num2, "es menor que ", str(num1))

In the previous line you open three parentheses and close two.

Since he does not know what is happening, the compiler continues processing the file, trying to complete the expression that he will use in the int() , until he finds a fragment of code that can not fit in what he is doing ( print(num2.. ) and that's where you mark the error.

    
answered by 15.10.2018 / 23:41
source