Write a recursive function to calculate the sum of first n natural numbers.
amannarayanm · updated · Python
def sum(num): if num==1 or num==0: return 1 else: sum_number = num + sum(num-1) return sum_number print(sum(10))
Click on the Run button to get started.
The code/input has changed since you last clicked on Run. Click it again to see the updated changes.