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

1

u/Smart_Tinker Apr 26 '26

It’s very complicated for a simple function.

I would do:

import time

def timer():
    time_end = time.time() + float(input(“How long for timer?”))
    while time.time() < time_end:
        time.sleep(1)
        print(int(time_end - time.time()))
    print(“Time’s up!”)

You also need some error handling in case someone enters a bogus time, like “a” or something.

1

u/wrg2017 Apr 27 '26

Wouldn’t this lock in the current time when the user is asked how many seconds, not when the user submits their response?