0% found this document useful (0 votes)
19 views3 pages

If Else Logic Programs

Uploaded by

arulsank2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

If Else Logic Programs

Uploaded by

arulsank2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ure!

Here are 10 different scenarios using if, elif, and else statements in Python:

1. Grade Evaluation:

python
Copy code
grade = 85
if grade >= 90:
print("You got an A!")
elif grade >= 80:
print("You got a B.")
elif grade >= 70:
print("You got a C.")
else:
print("You need to improve.")

2. Age Check:

python
Copy code
age = 18
if age < 13:
print("You're a child.")
elif age < 20:
print("You're a teenager.")
else:
print("You're an adult.")

3. Temperature Response:

python
Copy code
temperature = 30
if temperature > 30:
print("It's hot outside.")
elif temperature > 20:
print("The weather is nice.")
else:
print("It's a bit cold.")

4. Traffic Light:

python
Copy code
traffic_light = "red"
if traffic_light == "green":
print("You can go.")
elif traffic_light == "yellow":
print("Get ready to stop.")
else:
print("You must stop.")

5. User Login:
python
Copy code
username = "admin"
password = "1234"
if username == "admin" and password == "1234":
print("Login successful!")
elif username != "admin":
print("Invalid username.")
else:
print("Invalid password.")

6. Shopping Cart:

python
Copy code
items_in_cart = 5
if items_in_cart == 0:
print("Your cart is empty.")
elif items_in_cart < 5:
print("You have a few items.")
else:
print("You have a full cart.")

7. Weather Warning:

python
Copy code
wind_speed = 50
if wind_speed > 60:
print("Severe weather warning!")
elif wind_speed > 30:
print("Windy conditions.")
else:
print("Calm weather.")

8. Fuel Check:

python
Copy code
fuel_level = 15
if fuel_level < 10:
print("Refuel soon!")
elif fuel_level < 30:
print("Fuel level is low.")
else:
print("Fuel level is good.")

9. Password Strength:

python
Copy code
password = "myp@ssw0rd"
if len(password) < 8:
print("Weak password.")
elif any(char.isdigit() for char in password) and any(char.isalpha() for
char in password):
print("Strong password.")
else:
print("Moderate password.")

10. Event Planning:

python
Copy code
attendees = 20
if attendees < 10:
print("Consider canceling the event.")
elif attendees < 30:
print("The event will be small.")
else:
print("The event is well-attended!")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy