Question

[27] Write a recursive function to calculate the following for a given input value for x. result = 1+ 2+ 3 ..... + x For exam

(for python)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code in python is given below.

def serialAdd(x):
if x<=1:
return x
else:
return(x+serialAdd(x-1))

n=int(input("Please Enter a Number: "))
print("The result is:",serialAdd(n))



The screenshot of the running code is given below.

1 - def serialAdd(x): 2 if x<=1: 3 return x 4 - else: 5 return(x+serialAdd(x-1)) 6 7 n=int(input(Please Enter a Number: ))




Output for n=5 then result is 15
n=10 then result is 55





If the answer helped please upvote it means a lot. For any query please comment.

Add a comment
Know the answer?
Add Answer to:
(for python) [27] Write a recursive function to calculate the following for a given input value...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT