Question: Given a positive number num, the following code is trying to calculate and print the sum of natural numbers (i.e. positive integers greater than zero,

Given a positive number num, the following code is trying to calculate and print the sum of natural numbers (i.e. positive integers greater than zero, eg. 1,2,3...) up to num.

def sumup(num):

i=1

sum=0

while i <= num:

sum += I

return sum

Unfortunately, this code doesn't do what the author expects. What goes wrong, and how would you fix it?

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!