DEV Community

TANYA LYOP ACHAYI
TANYA LYOP ACHAYI

Posted on

Day 5 of 100.

Today was all about decisions. With if, elif, and else, I made Python think like a mini-brain. 🧠

Depending on the age I typed, it gave different responses, from “Enjoy your youth” to “Life keeps getting better.” It feels like I’m teaching Python how to reason!
😊😊😊🤭

PythonZeroToHeroStudent

100DaysOfPython

ConditionalStatements

Top comments (2)

Collapse
 
daemonic01 profile image
Dominik Kopócs • Edited

Nice work! Once you get comfortable with if-elif-else, you might also enjoy trying out Python's match-case. It's like the little sibling of if-else. Sometimes cleaner and more readable when checking multiple conditions. 😉

Here’s the same example using match-case with a little improvement. We check if the input is less than 1, as it cannot be real:

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

match age:
    case n if 1 > n:
        print("I don't think you were telling the truth.")
    case n if n < 18:
        print("You are still a teenager. Enjoy your youth! ")
    case n if 18 <= n < 30:
        print("Welcome to adulthood! ")
    case _:
        print("Life keeps getting better with age. ")
Enter fullscreen mode Exit fullscreen mode

If you feel like it, try adding another check to show the same message if an age greater than 120 is entered. ☺️

Collapse
 
lyop_achayi profile image
TANYA LYOP ACHAYI

I am definitely trying it.. 🥰🤭🙏🏾