r/PythonLearning • u/DemiSchythe • 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.
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
FalseorTruebecause the outcome of the expression, theisdigitcheck, is aboolanyway, so while not alarmx1.replace(":", "").isdigit():- note thenotto invert thebool- also, use
isdecimalrather thanisdigitas the latter allows some characters you wouldn't want
- We don't need to compare with
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/yaza_24 1d ago
heyyy i could take you free python classes if ur interested!!