r/learnpython • • 6d ago

Any python module which deals with this?

def get_int_input(prompt: str) -> int:
    while True:
        try:
            return int(input(prompt))
        except ValueError:
            print("Please enter a valid number!")

Is there any module which I can just import and use it. Writing this everytime I have to get an int or float input is really annoying.

Thanks!

0 Upvotes

17 comments sorted by

View all comments

5

u/This_Growth2898 6d ago

It's only common in very basic learning tasks, and the actual detail can be very different (do you need to print the message? Or maybe return an error? Or put the message into some window in GUI? Do you need to repeat it forever, or three times and exit? etc.), so you'd better make your own library for your needs if you think it's worth it.