Conditional Statements

Conditional Statements are used in programming to make decisions based on conditions.

They help a program choose what action to perform depending on whether a condition is True or False.

Understanding Conditional Statements in Python

Statement Type Usage
if statement Used when there is only one condition
if else statement Used when there are two choices
if elif else statement Used when there are more than two conditions

Real-Life Example

  • If it is raining → take an umbrella
  • Else → go outside normally

Just like this, Python programs make decisions.

Example

age = 18

if age >= 18:
    print("You can vote")
else:
    print("You are too young")

Output:

You can vote

Explanation

  • age >= 18 → checks condition
  • if → runs when condition is True
  • else → runs when condition is False

Types of Conditional Statements

  • if statement – checks a condition
  • if-else statement – gives two choices
  • if-elif-else – checks multiple conditions
  • nested if – condition inside another condition

Common Beginner Mistakes

  • Missing colon (:)
  • Wrong indentation
  • Using = instead of ==
  • Writing incorrect conditions

Why Use Conditional Statements?

  • Helps in decision making in programs
  • Makes apps and games smarter
  • Used in login systems, grading systems, and real-life applications

Real-World Uses

  • ATM machines checking balance
  • Login systems verifying passwords
  • Games deciding win/lose
  • School grading systems

Summary

  • Conditional statements help in decision-making
  • Based on True/False conditions
  • Use if, else, elif
  • Important for real-world programs

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What are conditional statements used for?

Conditional statements help programs make decisions.

Question 2

Which keyword is used to check a condition?

if is used to check conditions.

Question 3

What is the output?

age = 10

if age >= 18:
    print("Adult")
else:
    print("Child")

10 is less than 18, so else runs.

Question 4

Which statement is used for multiple conditions?

Question 5

What is the output?

x = 5

if x > 10:
    print("A")
elif x > 3:
    print("B")
else:
    print("C")

First is False, second is True → prints B.

Congratulations!

You've successfully mastered the knowledge check for "Conditional Statements."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Logical Operators Next Topic if Statement