Learn Python in Tamil | Python Basics | How to use Conditional Statements if ,elif, else

More Examples :

1. Basic if-else Statement:

number = 10
if number > 5:
 print("The number is greater than 5.")
else:
 print("The number is 5 or less.")

2. Multiple Conditions with elif:

marks = 85
if marks >= 90:
    print("Grade: A")
elif marks >= 75:
    print("Grade: B")
elif marks >= 50:
    print("Grade: C")
else:
    print("Grade: F")

3. Nested if Statements:

age = 25
if age >= 18:
    if age >= 21:
        print("Eligible for a full license.")
    else:
        print("Eligible for a provisional license.")
else:
    print("Not eligible for a license.")

4. Using Logical Operators:

score = 85
attendance = 90
if score > 80 and attendance > 85:
    print("You passed with good standing!")

5. Error Handling with Conditionals:

try:
    age = int(input("Enter your age: "))
    if age >= 18:
        print("You are eligible to vote.")
    else:
        print("You are not eligible to vote.")
except ValueError:
    print("Please enter a valid number.")

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *