Master Python Condition Statements in One Slide!" 🚀 if, elif, else 💡 Perfect for Beginners!

🐍 Python Day 3 & Day 4: Conditional Statements (if, elif, else)

⚙️ Day 3: if and else Statements

✅ Syntax:

if condition:

    # block of code

else:

    # block of code


✅ Example:

age = int(input("Enter your age: "))

if age >= 18:

    print("You are eligible to vote!")

else:

    print("You are not eligible to vote.")


⚙️ Day 4: if, elif, and else

✅ Syntax:

if condition1:

    # code block

elif condition2:

    # code block

else:

    # final block


✅ Example:

marks = int(input("Enter your marks: "))

if marks >= 90:

    print("Grade: A")

elif marks >= 75:

    print("Grade: B")

elif marks >= 60:

    print("Grade: C")

else:

    print("Grade: D")


💡 Important Notes:

Indentation (spaces/tabs) is mandatory in Python.


Conditions use comparison operators like ==, !=, >, <, >=, <=.


💪 Practice Exercises (Day 5 & 6):


1. Check if a number is even or odd.

2. Check if a person can vote (age ≥ 18).

3. Write a program to assign grades using if-elif-else.

4. Check if a number is positive, negative, or zero.

5. Use input() to take a number and print if it’s divisible by 3 and 5.


🔍 Output Sample:

Enter your marks: 85  

Grade: B



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.