How do you get Python to detect for no input

后端 未结 5 496
野趣味
野趣味 2020-12-11 07:04

I\'m new to coding in python and I was filling out some code that required a number of inputs. One thing it asked for was for the program to perform an action if the user pr

5条回答
  •  感情败类
    2020-12-11 07:34

    EDIT:

    what about something like this:

     try:
         coinN = input("Enter next coin: ")
         if coinN.isdigit(): # checks whether coinN is a number
             if coinN == "" and totalcoin == rand:
                 print("Congratulations. Your calculations were a success.")
             if coinN == "" and totalcoin < rand:
                 print("I'm sorry. You only entered",totalcoin,"cents.")
         else:
             raise ValueError
    
     except ValueError:
         print("Invalid Input")
     else:
         totalcoin = totalcoin + int(coinN) # convert coinN to int for addition
    

提交回复
热议问题