Question

An arithmetic sequence is a sequence of values where successive values have a common difference. For...

An arithmetic sequence is a sequence of values where successive values have a common difference.

For example, 2,5,8,11,... is an arithmetic sequence starting at 2 with a common difference of 3. We call the starting point s and the difference d.

Write a recursive Python function called arithmetic that takes values for s, d, and n, and returns the nth term of the arithmetic sequence.

Given the main function:

def main():
    for i in range(1,6):
        print(arithmetic(2,3,i))

the output will be:

2
5
8
11
14
0 0
Add a comment Improve this question Transcribed image text
Answer #1

'''function to genereate airthmetic sequence'''
def arithmetic(s, d, n):
if n == 0:
return 0
print(s)
arithmetic(s+d, d, n-1)

'''variable declaration and initialization'''   
s = 2
d = 3
n = 6

'''display message on the computer screen'''
print('The airthmetic sequence is: ')

'''function calling'''
arithmetic(s, d, n-1)

The screenshot of the above code is:

function to genereate airthmetic sequence def arithmetic (s, d, n): if n == 0: return 0 print(s) arithmetic(s+d, d, n-1) va

OUTPUT:

The airthmetic sequence is: 2 5 8 11 14

Add a comment
Know the answer?
Add Answer to:
An arithmetic sequence is a sequence of values where successive values have a common difference. For...
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