Conditional statements allow your program to make decisions and execute different blocks of code based on whether a condition evaluates to True or False.
if: Evaluates a condition; runs if true.
elif (Else If): Checks an alternative condition if previous ones failed.
else: A catch-all safety net that runs if none of the preceding conditions are true.
Notes:
Identation is very important
else is not a cumpulsory block, but it's good to have
Write a Python program that calculates a person's Body Mass Index (BMI) and categorizes their health status.
Formula:
BMI = weight / (height × height)
where:
Weight is measured in kilograms (kg)
Height is measured in meters (m)
BMI Categories:
Underweight: BMI < 18.5
Normal weight: 18.5 <= BMI <= 24.9
Overweight: 25.0 <= BMI <= 29.9
Obese: BMI >= 30.0
Expected Output:
Enter weight in kg: 70
Enter height in meters: 1.75
Your BMI is 22.86
Category: Normal weight
Write a Python program to check if a user can donate blood based on three rules:
Age: Must be between 18 and 65 inclusive.
Weight: Must be at least 50 kg.
Hemoglobin: Must be at least 12.5 g/dL.
Enter your age: 25
Enter your weight in kg: 68
Enter your hemoglobin level (g/dL): 13.5
Congratulations! You are eligible to donate blood today.
Write a Python program that determines whether a given year is a leap year.
Rules: A year is a leap year if it is divisible by 4, except for end-of-century years, which must be divisible by 400.
Mathematically: (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Enter a year: 2024
2024 is a leap year!
Write a Python program that takes three side lengths from a user.
First, check if the lengths form a valid triangle using the Triangle Inequality Theorem (the sum of any two sides must be strictly greater than the third side).
If valid, classify the triangle as Equilateral (all sides equal), Isosceles (two sides equal), or Scalene (all sides different).
Enter length of side 1: 5
Enter length of side 2: 5
Enter length of side 3: 5
This is a valid triangle: Equilateral