Syntax error in Python code. Which is? [closed]

1
print("**************")
print("Seja Bem Vindo")
print("**************")
numero_secreto = 65
chute = input("Digite um numero:")
print("Você digitou: ",chute)
if numero_secreto == chute
    print("você acertou")
else
    print("Você errou, Tente novamente")

I do not understand why it does not spin

    
asked by anonymous 16.12.2017 / 00:41

3 answers

1

There are syntax and logic errors. Syntax errors are easy to fix: the interpreter shows you an error message pointing to exactly the location and error.

Traceback (most recent call last):
  File "python", line 7
    if chute == numero_secreto
                             ^
SyntaxError: invalid syntax

You missed the colon, : , after if .

Traceback (most recent call last):
  File "python", line 9
    else
       ^
SyntaxError: invalid syntax

You missed the colon after else .

With these fixes your code will still not work, since the return of the input function will always be a string , so you will be comparing a string with an integer, which makes no sense and will never be true. Since you want to read an integer, you need to convert the value as such by doing:

chute = int(input("Digite um numero:"))

However, if the user enters any value other than numeric, an exception will be thrown. To resolve this problem, read:

How to make the system display an error message when it is not a number?

    
16.12.2017 / 00:50
2

Syntax error

print("**************")
print("Seja Bem Vindo")
print("**************")
numero_secreto = 65
chute = input("Digite um numero:")
print("Você digitou: ",chute)
if chute == numero_secreto:
    print("você acertou")
else:
    print("Você errou, Tente novamente")

See example OnLine

Example of if with else

if expression:
   statement(s)
else:
   statement(s)
) (% with%) and leave if also as integer so you can compare and have no problems comparing.

Source: Python IF ... ELIF ... ELSE Statements

    
16.12.2017 / 00:47
0

Then if and only put:, and when you use input and the expected result is an integer, use the function int ()

Fixed:

print("**************")
print("Seja Bem Vindo")
print("**************")
numero_secreto = 65
chute = int(input("Digite um numero:"))
print("Você digitou: ",chute)
if numero_secreto == chute:
    print("você acertou")
else:
    print("Você errou, Tente novamente")
    
16.12.2017 / 00:51