Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3 Program: Ask user to enter numbers. When user enters nothing, the program prints all the numbers read so far and processes the collection
Python 3 Program:
Ask user to enter numbers. When user enters nothing, the program prints all the numbers read so far and processes the collection of numbers using a for loop. When the program is processing the collection, if a zero is encountered the program should end immediately printing only the word "Done," (use a break for this). Negative numbers should be ignored (use a continue for this; I know you can also do this with a condition, but I want you to practice with continue). If no zero is encountered, the program should display the sum of all numbers (do this in an else clause). Always display "Done" at the end of the program. Test your program with the collection ( 12, 4, 3, 33, -2, -5, 7, 0, 22, 4 ). With these numbers, the program should display only the list of numbers followed by "Done." If you remove the zero, it should display 85 (and "Done"). After the program prints done it ends.
examples
% enter a number: 12 enter a number: 4 enter a number: 3 enter a number: 33 enter a number: -2 enter a number: -5 enter a number: 7 enter a number: 0 enter a number: 22 enter a number: 4 enter a number: [12.0, 4.0, 3.0, 33.0, -2.0, -5.0, 7.0, 0.0, 22.0, 4.0] Done % python3 ch12_05.py enter a number: 12 enter a number: 4 enter a number: 3 enter a number: 33 enter a number: -2 enter a number: -5 enter a number: 7 enter a number: 22 enter a number: 4 enter a number: [12.0, 4.0, 3.0, 33.0, -2.0, -5.0, 7.0, 22.0, 4.0] total: 85.0 Done % python3 ch12_05.py enter a number: 0 enter a number: [0.0] Done % python3 ch12_05.py enter a number: 0 enter a number: -1 enter a number: -2 enter a number: -3 enter a number: [0.0, -1.0, -2.0, -3.0] Done % python3 ch12_05.py enter a number: -1 enter a number: -2 enter a number: -3 enter a number: [-1.0, -2.0, -3.0] total: 0 Done % python3 ch12_05.py enter a number: -1 enter a number: -2 enter a number: -3 enter a number: 5 enter a number: 3 enter a number: [-1.0, -2.0, -3.0, 5.0, 3.0] total: 8.0 Done %
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started