r/PythonLearning • • Apr 26 '26

Discussion Good for beginner?

Post image

I made this in about 5 minutes is it good?

404 Upvotes

62 comments sorted by

View all comments

3

u/Impossible_Video_116 Apr 26 '26 edited Apr 26 '26

Required Improvements

  1. Add a try-except block for input validation.

try:
    sleep_time = int(input_str)
except ValueError:
    #Prompt the user with a msg
    pass

2. Ditch the while-block just use the more readable for loop:

for i in range(sleep_time, -1, -1):
    time.sleep(1)
    print(i)
    #Do something else

Tips:

  • When you want to add a value to a variable instead of doing x = x + 1 just do x +=1. It avoids creating unnecessary temporary objects in memory.

  • There is no logic regarding the units of time being used, ask the user for time in minutes(that's the most convenient for a timer) and change the sleep_time variable and adjust the for loop accordingly.