“Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss” Code-Antworten

Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss

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
Smoggy Sandpiper

Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss

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
Smoggy Sandpiper

Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss

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
Smoggy Sandpiper

Ähnliche Antworten wie “Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss”

Fragen ähnlich wie “Wie man entscheidet, dass die Eingabe eine Ganzzahl von weniger als 5 in Python sein muss”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen