Please help on the below query.
secret_number= 100
guess = int(input(“Guess the correct secret number:”))
while guess != secret_number
guess=int(input((“Guess the correct secret number:”))
else:
print(“you guessed it right”)
This is similar to what has been provided in the lecture, however when I try to run the above code, it throws an error.
" File “main.py”, line 5
else:
^
SyntaxError: invalid syntax"
HI @mahesh.kumar.sridhar
A couple of things here.
- Indentation - it is part of the syntax! When pasting code, please use code blocks so we can check indentation. That’s the
</>
button in the post editor.
- You’ve missed a
:
after the while
statement. All blocks are introduced with a :
This is the working code
secret_number= 100
guess = int(input("Guess the correct secret number:"))
while guess != secret_number:
guess=int(input("Guess the correct secret number:"))
else:
print("you guessed it right")