“Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie” Kod odpowiedzi

Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie

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

Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie

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

Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie

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

Odpowiedzi podobne do “Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie”

Pytania podobne do “Jak zdecydować, że dane wejściowe musi być liczbą całkowitą mniejszą niż 5 w Pythonie”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu