Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider three sequences (Un), (Vn), and (W,) of integers defined recursively fo

ID: 3788934 • Letter: C

Question

Consider three sequences (Un), (Vn), and (W,) of integers defined recursively for any n 2 n-1 t U (1) (2) W. n-1 X will write a function that, given three numbers, identifies which of these In this question, you three sequences these numbers follow, and outputs the next term in that sequence. More precisely, write a function with the following header: function Inext term] my sequence id (a, b, c) where: a, b, and c are scalars of class double that represent integers next term is a scalar of class double (see below for description) If a, b, and d c (in this order) cannot be three consecutive terms of any of the three sequences (Un), (Vn), and (Wn), then next term should have the value NaN. If a, b, and c (in this order) can be three consecutive terms of one of the three sequences (Un), (Vn), and (Wn), then next term should be the next term in that sequence. If there are multiple distinct choices for next term, then next term shoul have the value NaN. For example, if a b, and c have the values 2, 2, and 4 (respectively), tential values for next term are 6 according to sequence (Un) and 8 according to sequence (Wa). In this example, next term should have the value NaN. If a, b, and c can be three consecutive terms of more than one of the sequences but the corresponding next terms are all equal, then next term should have the value of this next term. For example, the values 0, 0, and 0 can be three consecutive terms of any of the three sequences, but the next term in the sequence is 0 in each case. In this example, next term should have the value 0.

Explanation / Answer

# Python code for given problem statement.
print "Enter the value of a,b,c"
a=input()
b=input()
c=input()
u=0
v=0
w=0
if(a+b==c): #checks Un is satisfied or not
   u=1
   un=b+c
if(b-a==c): # checks Vn is satisfied or not
   v=1
   vn=c-b #next term of Vn sequence
if(a*b==c): #checks Wn is satisfied or not
   w=1
   wn=c*b #next term of Wn sequence
if(u==1 and v==1 and w==1): #Checks whether all sequences are satisfied or not
   if(un==vn==wn):
       print un
   else:
       print "NaN"

elif(u==0 and v==0 and w==0): #Checks none of sequence is satisfied
   print "NaN"
elif (u==1): # checks Un is satisfied or not
   if(v==0 and w==0):
       print un
   elif(v==1 and un==vn):
       print un
   elif (w==1 and un==wn):
       print wn
   else:
       print "NaN"
elif (v==1): # checks Vn is satisfied or not
   if(u==0 and w==0):
       print vn
   elif(u==1 and un==vn):
       print un
   elif (w==1 and vn==wn):
       print wn
   else:
       print "NaN"
elif (w==1): # checks Wn is satisfied or not
   if(u==0 and v==0):
       print wn
   elif(v==1 and wn==vn):
       print wn
   elif (u==1 and un==wn):
       print wn
   else:
       print "NaN"

#Output :

Enter the value of a,b,c
2.4234
45.777
454.44
NaN

Enter the value of a,b,c
2
4
6

10