Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Assume that you have stored a list of numbers in a variable called aList. You should NOT initialize this list, just use the variable name

Assume that you have stored a list of numbers in a variable called aList. You should NOT initialize this list, just use the variable name in your code and assume it holds a list of numbers.
You do not know how many numbers are in aList, and your program should work for anylength list. Remember, you know how to find the length of any list using a python function.
Hint, you will need to find the length of aList! Problem: Given a list of numbers (described above) use a while loop to compute the sum of the number in the list and store it in a variable called total. Values will be added one at a time inside the loop to total until all values in the list have been added in. You will access the list values using their INDEXES. That means you need a variable to hold the current index. Call that variable index.Do not use built-in functions like sum, you must add one value at a time to total in the loop.
NO use of break or continue allowed, you must properly structure your loop with the loop variable initialization before the loop starts, test of the loop variable in the loop statement, update of the loop variable in the loop, generally (and in this case) the update will be the last statement in the loop. After the loop is over, print the value of total. Below are specific questions about this problem. There are 6 questions, then there is
writing the code. Point values given below.
(a) Write  expression in python that will give you the length of the variable aList:

(b) To think about the problem it can be helpful to use an actual example and to write notes, see how that would work. Here is an example list: [2, 6, 1, 4] Write the INDEXES for this list under the values: ---------
(c) Assume the list in part (b) is stored in the variable aList, write an expression that uses the correct index to refer to the value 6 in aList.
Note
(d) List all the variables you think you will need for this problem. Write their name, then a short description of what they hold, and how they get their initial value. For aList you can just write "given" for the initial value

(e) What variable is the loop variable in this problem? Note, the loop variable is the one whose value determines when the loop will stop:

(f) What condition will cause the loop to stop and why?

Step by Step Solution

3.47 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

Python code to find the sum of values in a given list aList initialize total and index to 0 total 0 hold the total of values in the list index 0 holds ... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students explore these related Programming questions