Control flow structures allow your program to make decisions based on conditions. The if
statement is used for this purpose.
The if
statement is used to test conditions. If the condition is True, the code inside the block runs:
age = 18
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Write a program that checks whether a number is even or odd.
if
statement in Python?if
statement is False?Answers: The if
statement checks a condition and runs code if the condition is True. If the condition is False, the code inside the else
block will run (if defined).