← Back to Python

All Topics

Advertisement

Learn/Python/Python Fundamentals

Conditional Statements

Topic: Basics

Advertisement

Introduction

Conditional statements allow you to execute code based on certain conditions.

If Statement

age = 18

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

Ternary Operator

status = "Adult" if age >= 18 else "Minor"

Multiple Conditions

score = 85
attendance = 90

if score >= 90 and attendance >= 80:
    print("Excellent")
elif score >= 70 or attendance >= 70:
    print("Good")
else:
    print("Needs improvement")

Practice Problems

  1. Grade calculator (A, B, C, D, F)
  2. Leap year checker
  3. BMI calculator with health categories
  4. Traffic light simulator
  5. Password strength validator

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →