Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Review the following bad Loop code. The purpose of the code is to sum all the numbers in the numbers list; it functionally achieves this

Review the following "bad" Loop code. The purpose of the code is to sum all the numbers in the numbers list; it functionally achieves this goal but the code is problematic. What problems do you see with the code? What would you change and why?
Note: It is ok if your answers overlap with your classmates, but if possible, try to find new problems with the code that your classmates have not yet posted.
Example of a bad Loopnumbers =[1,2,3,4,5]
total =0
for i in range(Len(numbers)):
if i==0 :
total += numbers [i]
elif i==1 :
total += numbers [i]
elif i=2 :
total += numbers [i]
elif i==3;
total += numbers [i]
elif i=4 :
total += numbers [i]
else:
print("This should never happen!")
print("The total is:", total)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

=+ Develop familiarity with performance appraisal techniques.

Answered: 1 week ago

Question

How do books become world of wonder?

Answered: 1 week ago