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

1. Write a getInt() method that takes as input a String prompt and a Scanner, an

ID: 3565186 • Letter: 1

Question

1. Write a getInt() method that takes as input a String prompt and a Scanner, and returns an integer. This method prompts a user for an integer. If the entered value is an integer, then it is returned. If it is not an integer, then this method must re-prompt until an integer is entered.

2. Write a getLucasSequence() method that takes as input integer parameters p, q and n. Where p and q are Lucas parameters as de?ned above and n determines how many Lucas numbers are generated. This method returns an ArrayList of integers: Lpq(0),Lpq(1),Lpq(2),...,Lpq(n)

3. Write a checkSequence() method that takes as input an ArrayList of integers, identi?es the ?rst i that is greater than or equal to 2 for which Lpq(i) ? i^4 and prints out: i : Lpq(i) i^4 If there is no such i, then this method must print out

Explanation / Answer

1) '''
    check is function to check p,q and r given by user are integers.
   '''
   def check(p,q,n):               
        for i in range(len(p)):
            if (ord(p[i]) >= 48 and ord(p[i]) <= 57):
                continue
            else:
                return false
       for i in range(len(q)):
            if (ord(q[i]) >= 48 and ord(q[i]) <= 57):
                continue
            else:
                return false
        for i in range(len(n)):
            if (ord(n[i]) >= 48 and ord(n[i]) <= 57):
                continue
            else:
                return false

2)
Python code to compute getLucasSequence from 0 to n and store them in a list.

def getLucasSequence(p,q,i):
   if (i == 0):
       return 0
   elif (i == 1):
       return 1
   else:
       return p*getLucasSequence(p,q,i-1) - q*getLucasSequence(p,q,i-2)

def compute(p,q,n):
   l = []
   for i in range(n+1):
       l.append(getLucasSequence(p,q,i))
   return l

3)
def checkSequence(l):
   for i in range(2,len(l)):
       if (l[i] >= i^4):
           return i
   return