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
  • give an example of an arithmetic sequence that is found in the real world. find the common difference and write a recursive and iterative rule for the sequence. then give an example of a geometric tha...

    give an example of an arithmetic sequence that is found in the real world. find the common difference and write a recursive and iterative rule for the sequence. then give an example of a geometric that is found in the real world. find the common ratio and write ac recursive and iterative rule for the sequence. use a rule to find any term.

  • Below you will find a recursive function that computes a Fibonacci sequence (Links to an external...

    Below you will find a recursive function that computes a Fibonacci sequence (Links to an external site.).   # Python program to display the Fibonacci sequence up to n-th term using recursive functions def recur_fibo(n): """Recursive function to print Fibonacci sequence""" if n <= 1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) # Change this value for a different result nterms = 10 # uncomment to take input from the user #nterms = int(input("How many terms? ")) # check if the number...

  • what are the similarities and differences between an arithmetic sequence and a linear equation

    what are the similarities and differences between an arithmetic sequence and a linear equation?ok i know that arithmetic sequence is a sequence of real numbers for which each term is the previous term plus a constant (called the common difference). For example, starting with 1 and using a common difference of 4 we get the finite arithmetic sequence: 1, 5, 9, 13, 17, 21; and also the inifinite sequence 1, 5, 9, 13, 17, 21, 25, 29, . . .,...

  • 13. In an arithmetic sequence , +7. If I =-5 determine the values of I, and...

    13. In an arithmetic sequence , +7. If I =-5 determine the values of I, and to show the calculations that lead to your answers 14. If x4,2x+5 and 4x + 3 represent the first three terms of an arithmetic sequence, then find the value of x. What is the fourth term? 15.18 S(1)=12 and f() = S(n-1)- 4 then which of the following represents the value of S(40)? (1) -148 (3) - 144 (2) - 140 (4) -172 16....

  • find a11 of an arithmetic sequence when a1=8 and the common difference d= -3

    find a11 of an arithmetic sequence when a1=8 and the common difference d= -3

  • The Lucas Numbers are a sequence very similar to the Fibonacci sequence discussed in class, the...

    The Lucas Numbers are a sequence very similar to the Fibonacci sequence discussed in class, the only difference being that the Lucas Numbers start with 10-2 L,-1 as opposed to Fibonacci's Fo = 0 and F1 = 1, concretely, they are defined by Lo = 2, L,-1 and Ln-Ln-l + Ln-2 for n > 1 Write a Python function called first D_digit Lucas that takes an integer argument D less than 30 and returns the first D-digit Lucas number. For...

  • In Python Trace "Stars.py" by drawing a table that shows the values of relevant variables (row...

    In Python Trace "Stars.py" by drawing a table that shows the values of relevant variables (row and star) and keeping track of the output. This program contains a nested for loop, so for each iteration of the outer loop, the inner loop executes in its entirety: row star 1 1 2 1 2 2 3 1 3 2 3 3 ... ... #******************************************************************** # stars.py # # Demonstrates the use of nested for loops. #******************************************************************** #----------------------------------------------------------------- # Prints a triangle...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • Concurrent Powers The following code returns the results of the integers in a list of values...

    Concurrent Powers The following code returns the results of the integers in a list of values to the power of input p. Rewrite this as concurrent code in Python, using concurrent.futures. In the concurrent version, it is not necessary for results to be printed in the same sequence as is output by the code below. values = [2,4,6,8,10] def powers(val,po):     return val ** po def non_concurrent_powers(p):     for val in values:         res = powers(val,p)         print('%s to the...

  • Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n):...

    Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...

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