Question: Problem 3 . 4 . Errors in summation The following code is supposed to compute the sum s = PM k = 1 1 (

Problem 3.4. Errors in summation
The following code is supposed to compute the sum s =
PM
k=1
1
(2k)
2, for M =3.
s =0
M =3
for i in range(M):
s +=1/2*k**2
print(s)
The program has three errors and therefore does not work. Find the three errors
and write a correct program. Put comments in your program to indicate what
the mistakes were.
There are two basic ways to find errors in a program:
1. Read the program carefully line by line, and think about the consequences
of each statement. Look for inconsistencies in the form of variables being
used before they are defined, and perform the calculations in the statements
by hand to see how variables change their value.
6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!