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
Get step-by-step solutions from verified subject matter experts
