Previous

If-Else Statements

1 / 6
Next

If statements are a crucial building block for programs. An if statement executes its indented code block based on whether a Boolean value is true or false.

if (n == 0):
  print("n is zero")
else:
  print("n is not zero")
print("Goodbye")

The double equal sign == yields either True or False based on whether or not n has value 0. The code blocks are indented to indicate that they belong to the if or the else. The "Goodbye" is printed in either case.

if (n == 0):
  print("n is zero")
else:
  print("n is not zero")
  print("Goodbye") # only printed if n is not zero
Send

My first if statement

Hint
Beginner

Input a password. If the password equals Password123!, the program should print Authenticated. Otherwise, it should print Wrong password.

Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!