“bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di python” Kode Jawaban

bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di 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
Smoggy Sandpiper

bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di 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
Smoggy Sandpiper

bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di 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
Smoggy Sandpiper

Jawaban yang mirip dengan “bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di python”

Pertanyaan yang mirip dengan “bagaimana memutuskan bahwa input harus bilangan bulat kurang dari 5 di python”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya