If else statement



what is the syntax error?

@Amrita_dey
Firstly, if you want to create a python file then use .py extension it indicates that your file contain python document. You created file- name if_condition ,which is wrong.
Run the command - sudo nano filename.py
in your case - sudo nano if_condition.py

@Amrita_dey
Also your code contain some mistakes like in 2nd line - “yes”:
In 6th line - statement.")



write the code in same way as in image and the output of the code is also there.

@Amrita_dey

You have missed the ‘:’ semicolon (at the end of condition) in the if homework_done == yes: condition.

Also, there seems to be an identation error on the last line. Make sure the “outside conditional statement” print line is on the same row as ‘else’ line.
Some what like this -

else:
   print("Inside the conditional block")
print("Outside the conditional block")
1 Like

@Amrita_dey as the error displayed by compiler mentioned the error is in line 2 and which is in if statement if you look closely you missed the semicolon “:” after the if condition which result in the error. Still it may show error as you have mismatched the indention in the last line of the code so have to correct it too and match it to the else statement.