Indentation
You might have noticed that the commands following the if
or else
statements are indented. This indented code is called a block of code. It's important that when the condition of an if
statement is true, it is not just the following line that executes but the indented block of code. For example:
password = "123456"
if password == "123456":
print("The password is very weak")
print("Please choose a stronger password")
print("The program will now exit")
Here, if the password
equals 123456
, the indented block of code is executed. In this case, it prints The password is very weak
and Please choose a stronger password
. Then, independently of the if
statement, it prints The program will now exit
.
The same applies to the else
statement - if the if
condition is false, the indented block of code following the else
statement is executed.
Instructions
On line 6, print It is too expensive
. Make sure the print
statement is within the indented block of the else
statement.
Start programming for free
4/10