Question
Q3: Sum fun! (Loop algorithms: Sum of values) Instructions This week we will step through some common loop algorithms. To start us off, we will
Q3: Sum fun! (Loop algorithms: Sum of values)
Instructions
This week we will step through some common loop algorithms. To start us off,
we will obtain a sum of values.
Your task is to fix the code so that it does what is expected/described below.
Details
Input
The program reads in the following:
an integer values (unknown quantity, each on their own line)
followed by one empty line (empty string )
Processing
Sum of values algorithm:
Initialize total to 0
Read in a value (make sure to convert it to proper data type)
Use while loop with looking for sentinel, each time through loop:
Add entered value to total
Read in another value (make sure to convert it to proper data type)
Output
Output the sum of the values.
Sample input/output:
Input | Output |
---|---|
3 4 5 | The sum of the values is 12. |
\# Input total =0.0 inputString = input("Enter value: ) while inputString !=" value=int(inputString)inputString=input("Entervalue: )total+=valueprint(Thesumofthevaluesis+str(total)+)
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