How to make users only enter integer values in Python program

后端 未结 5 1364
别跟我提以往
别跟我提以往 2020-12-20 07:33

I have a homework assignment that I am very confused about. I have to write a program allowing users to input the number of eggs that they are buying. The program will then

5条回答
  •  被撕碎了的回忆
    2020-12-20 07:43

    while True:
        try:
           amount=int(input("how many do you want to buy"))
           break
        except ValueError:
           print("Please Enter An Amount")
           continue
        else:
            break
    

    This is a simple way of making the user inputs an integer in python 3. This can also be for making sure the user inputs a string all you need to do for this is just change int(.into str(

提交回复
热议问题