very basic recursion function expected to print the value of sum upto the entered number from 1, but prints the out put several times, instead of only ones. however if I add exit() after print, it works. Please help what is wrong in this code, as I dont want to use exit(). kindly help
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
def recsum (entnf,sumf): while entnf>0: sumf=sumf+entnf entnf-=1 recsum(entnf,sumf) print("Condition failed, coming out of the loop") print("Sum is: ", sumf) #exit() print("ENter the number for which you want to calculate sum upto 0: ") numbr = int(input()) print("Entered # is: ",numbr) sum = 0 recsum(numbr,sum)The output is:
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6
Condition failed, coming out of the loop
Sum is: 6