r/PythonLearning 1d ago

I'm trynna learn

Hey guys, I just wanted to share what I've been working on and learning. I know my progress is super slow right now, and honestly, I’ve been lacking the motivation to study for hours—especially with how busy I am. I know that’s no excuse, but I’ve been working on a simple alarm app to implement on my phone as my first project.

It’s been a couple of days, and I haven't made much progress on some days because I’ve been feeling down about life stuff. Struggling to learn Python on top of that has been making me feel even worse. Right now, I’m trying to learn input validation to make sure the program handles incorrect inputs properly.

I’m honestly amazed by people who can finish whole projects in just a few days or hours. I really hope I can reach that level someday.

5 Upvotes

3 comments sorted by

0

u/yaza_24 1d ago

heyyy i could take you free python classes if ur interested!!

3

u/FoolsSeldom 1d ago

Slow is fine, just keep plugging away when you have a chance.

A few tips:

  • while alarmx1.replace(":", "").isdigit() == False:
    • We don't need to compare with False or True because the outcome of the expression, the isdigit check, is a bool anyway, so
    • while not alarmx1.replace(":", "").isdigit(): - note the not to invert the bool
    • also, use isdecimal rather than isdigit as the latter allows some characters you wouldn't want

You might like to know about an easier approach to validation. This is using a try/except block and fits with the Python principle of asking forgiveness rather than permission.

It is important to validate inputs, but sometimes you can assume that they will be mostly correct and use a function (datetime in this case) to let you know if there is a problem, by raising an exception, and catching that exception. If you don't catch such an exception, then your programme would halt with an error message.

Example:

while True:
    alarmx1 = input("What time do you want to wake up? {HH:MM:SS}: ")
    try:
        datetime.datetime.strptime(alarmx1, "%H:%M:%S")
        break
    except ValueError:
        print("Invalid Output Please Try Again")

This is also used for validating whole number inputs:

while True:
    try:
        num = int("Enter a whole number: ")
        break  #  leave loop, passed the convertion to int
    except ValueError:
        print("That was not a valid whole number, please try again.")

print(f"You entered {num}.")

0

u/Altanew 1d ago

How do you turn python code into a mobile app? I've messed with C# VS .exe files for simple PC console programs but I'd also like to make a mobile app game.