Unlike other programming languages, python uses indentation to define the scope or block of code for statements such as if
, for
, while
, def
, class
etc. The number of spaces at the start of a line of code is called indentation. You need to have the correct indentation for the code to work properly.
you are missing indentations in IF and ELSE code blocks.
In this code that you have written you have not used indentation properly.Indentation is really important while coding in python .You should have written the code as shown in the example below.
maths=“yes”
if maths==“yes”:
print(“You will get toffee”)
else:
print(“You will not get anything”)
print(“Outside of conditional statements”)
It was an indentation error.So you can write your code like this:
maths = “yes”
if(maths == “yes”):
print(“You will get toffee”)
else:
print(“You will not get anything”)
print(“Outside the conditional statement”)
The issue with the provided code is an indentation error. In Python, indentation is crucial to define the scope of code blocks. Additionally, there seems to be a typographical issue with the quotes around the string “yes” in the first line.
Here’s the corrected version of your code:
maths = “yes”
if maths == “yes”:
—print(“you will get toffee”)
else:
— print(“you will not get anything”)
print(“outside the conditional statement”)
— is the indentation gap
In this corrected code, the indentation is proper, and the program will execute as expected. It will print “you will get toffee” if the value of maths is “yes” and “you will not get anything” otherwise. Finally, it will print “outside the conditional statement” regardless of the condition’s outcome.