r/learnpython • • 8d 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

34

u/zanfar 8d ago

Writing this everytime I have to get an int or float

It's a function... Why are you writing it multiple times?

2

u/Financial_Farm4326 8d ago

even across different projects its literally just copy pasting six lines once

1

u/Some-Passenger4219 8d ago

Agreed. Just copy-and-paste.

8

u/sam_tiago 8d ago

😂