Loading...
Loading...
Loading...
A web form sends the quantity of an order as text. Read one line. If it is a whole number, print Quantity: followed by the number. If it is not, print Invalid quantity.
Use try and except, so the program never crashes.
Quantity: <number> or Invalid quantity.Example 1
Input
5
Output
Quantity: 5
A plain whole number.
Example 2
Input
abc
Output
Invalid quantity
Letters cannot become a number.
Try the problem first. Open one hint at a time.
int() raises ValueError when the text is not a whole number.
Put the conversion and the print of the good case inside try, and the other message in except ValueError.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor