Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to decide that the input must be a integer less than 5 in python

def getUserAmount():
    while True:
        amount = input("Enter amount: ")
        try:
            value = int(amount)
            if value >= 0:
                break
            else:
                print("Amount is negative, try again")
        except ValueError:
            print("Amount must be a number, try again")

    return value

main()
# NOTE
# Found this on "stack overflow" (I didn't write the code) (Below is the link of the page)
# https://stackoverflow.com/questions/33112377/python-verifying-if-input-is-int-and-greater-than-0
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #decide #input #integer #python
ADD COMMENT
Topic
Name
6+9 =