+ 2
How to write a program that would keep taking inputs from the user until the sum of all the inputs reach 200,
The numbers permissible for the user input are: 10, 20 and 50. If any other number is entered, then the program should declare it as invalid. I've tried the following but it doesn't seem to work out: count = 0 total = 0 print("Enter the values of amounts collected") while True: new_number = input('> ') count = count + 1 total = total + int(new_number) if total==200 : print("You have successfully collected 200") break if total>200: print("Amount collected exceeds 200") break Sample input: > 10 > 50 > 50 > 50 > 10 > 20 > 10 Sample output: You have successfully collected 200 Sample input: > 190 ... Sample output: Invalid input Sample input: > 50 > 50 > 50 > 20 > 50 Sample output: Amount collected exceeds 200
4 Answers
+ 2
Alternative solution..😊
https://code.sololearn.com/cjHaQ2OtD6Gx/?ref=app
+ 1
Use a while loop and exit when the sum >= 200
0
MsBonnie
Here is a solution of your problem but what if amount is less than 200?
https://code.sololearn.com/cajiW4FSyOFs/?ref=app
- 1
MsBonnie
Why you are passing '> ' in input function. No need to do that. Just do this
new_number = input()
To handle invalid input just use try except block