Question

In: Computer Science

PYTHON The nth term of the sequence is given by: Xn = (2 ∗ Xn-3) +Xn-2+/...

PYTHON

The nth term of the sequence is given by: Xn = (2 ∗ Xn-3) +Xn-2+/ + (4 ∗ Xn-1)

For example, if the first three values in the sequence were 1, 2 and 3. The fourth value would be: (2 * 1) + 2 + (4 * 3) = 16 Replacing the previous three Integers (2, 3 and 16) in the formula would determine the fifth value in the sequence. The nth term can be calculated by repeating this process. Write a program that includes two functions main() and calculate()which are used to determine the nth term in the sequence.

The main() function: • Displays a description of the program’s function • Prompts the user for the number of values in the sequence (n) • Prompts the user for the first three values in the sequence • Using a loop, calls the calculate() function repeatedly until the nth value is determined • Displays the nth value of the sequence

The calculate() function: • Accepts three values as arguments • Calculates the next value in the sequence • Returns the calculated value

Solutions

Expert Solution

Pseudo code

1) Take the input for the value of n

2) Take first 3 input values

3) iterate in loop from 0 to n-3

4) call the calculate function and append the returned value to the list

5) print the result

// Code

def calculate(a,b,c):
return 2*a+b+4*c # calculation

# Main Driver Code

print("Enter Number of vlaues in the sequence:")
n=int(input()) #it takes the input for the value of n
print("Enter first 3 values:")
li=list(map(int,input().split())) # it takes first three values

for i in range(0,n-3): # loop to calculate values
li.append(calculate(li[i],li[i+1],li[i+2])) # function call
print(str(n)+"th value of the series is "+str(li[-1]))

// OUTPUT

Enter Number of vlaues in the sequence:                                                                                                                                      

4                                                                                                                                                                            

Enter first 3 values:                                                                                                                                                        

1 2 3                                                                                                                                                                        

4th value of the series is 16                                                                                                                                                

                                                                                                                                                                             

                                                                                                                                                                             

...Program finished with exit code 0                                                                                                                                         

Press ENTER to exit console.   

// Code Images

//OUTPUT IMAGE


Related Solutions

For each sequence given below, find a closed formula for an, the nth term of the sequence (assume...
For each sequence given below, find a closed formula for an, the nth term of the sequence (assume the first terms here are always a0) by relating it to another sequence for which you already know the formula. −1,0,7,26,63,124,… an=(n^3)-1 −1,1,7,17,31,49,… an=2n^2-1 0,10,30,60,100,150,..... an=10*((n(n+1))/2) 2,3,6,14,40,152,… an= The first three are correct I can't figure out the last one.
Use the formula for the general term​ (the nth​ term) of an arithmetic sequence to find...
Use the formula for the general term​ (the nth​ term) of an arithmetic sequence to find the sixth term of the sequence with the given first term and common difference. a1 =15; d=7 a6 =
Given the following series: 1, 2, 5, 26, 677, ….. such that the nth term of...
Given the following series: 1, 2, 5, 26, 677, ….. such that the nth term of the series equals to (n-1)th ^2 +1 and the first term of the series is 1. Write a C program using recursive function named f to compute the nth term. Use for loop to print the values of first n terms in the series. You will take input n from the user. Example output: Enter number of terms: *value* *numbers here* nth term: *value*...
. Suppose that the sequence (xn) satisfies |xn –α| ≤ c | xn-1- α|2 for all...
. Suppose that the sequence (xn) satisfies |xn –α| ≤ c | xn-1- α|2 for all n. Show by induction that c | xn- α| ≤ c | x0 - α|2n , and give some condition That is sufficient for the convergence of (xn) to α. Use part a) to estimate the number of iterations needed to reach accuracy |xn –α| < 10-12 in case c = 10 and |x0 –α |= 0.09.
Let {xn} be a real summable sequence with xn ≥ 0 eventually. Prove that √(Xn*Xn+1) is...
Let {xn} be a real summable sequence with xn ≥ 0 eventually. Prove that √(Xn*Xn+1) is summable.
Let (Xn) be a monotone sequence. Suppose that (Xn) has a Cauchy subsequence. Prove that (Xn)...
Let (Xn) be a monotone sequence. Suppose that (Xn) has a Cauchy subsequence. Prove that (Xn) converges.
a real sequence xn is defined inductively by x1 =1 and xn+1 = sqrt(xn +6) for...
a real sequence xn is defined inductively by x1 =1 and xn+1 = sqrt(xn +6) for every n belongs to N a) prove by induction that xn is increasing and xn <3 for every n belongs to N b) deduce that xn converges and find its limit
Let (xn) be a sequence with positive terms. (a) Prove the following: lim inf xn+1/ xn...
Let (xn) be a sequence with positive terms. (a) Prove the following: lim inf xn+1/ xn ≤ lim inf n√ xn ≤ lim sup n√xn ≤ lim sup xn+1/ xn . (b) Give example of (xn) where all above inequalities are strict. Hint; you may consider the following sequence xn = 2n if n even and xn = 1 if n odd.
2. Consider the stochastic process {Xn|n ≥ 0}given by X0 = 1, Xn+1 = I{Xn =...
2. Consider the stochastic process {Xn|n ≥ 0}given by X0 = 1, Xn+1 = I{Xn = 1}Un+1 + I{Xn 6= 1}Vn+1, n ≥ 0, where {(Un, Vn)|n ≥ 1} is an i.i.d. sequence of random variables such that Un is independent of Vn for each n ≥ 1 and U1−1 is Bernoulli(p) and V1−1 is Bernoulli(q) random variables. Show that {Xn|n ≥ 1} is a Markov chain and find its transition matrix. Also find P{Xn = 2}.
For any sequence (xn) of real numbers, we say that (xn) is increasing iff for all...
For any sequence (xn) of real numbers, we say that (xn) is increasing iff for all n, m ∈ N, if n < m, then xn < xm. Prove that any increasing sequence that is not Cauchy must be unbounded. (Here, “unbounded” just means that xn eventually gets larger than any given real number). Then, show that any increasing sequence that is bounded must converge
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT