Loading...
Loading...
An account starts with a balance. The first line is the balance. The second line is the number m of requests. The next m lines are withdrawal amounts typed as text.
For each request: if the text is not a whole number, or is 0 or less, print Invalid amount. If it is more than the balance, print Insufficient funds. Otherwise subtract it and print Withdrew <amount>, balance <balance>.
Example
Input
500 3 200 900 abc
Output
Withdrew 200, balance 300 Insufficient funds Invalid amount
One good, one too large, one invalid.
Try the problem first. Open one hint at a time.
Convert in one try and print Invalid amount on ValueError. Then check the rules in a second try that raises ValueError with the message.
Use else to subtract and print only when no error occurred.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor