In: Computer Science
Can you answer these question using python and recursive functions
Write a function that consumes two numbers N1 and N2 and prints out all the even numbers between those numbers, using recursion.
Using any number of list literals of maximum length 2, represent the data from your Survey List. So you cannot simply make a list of 15 values. Make a comment in your code that explicitly describes how you were able to represent this.
Write a recursive function that traverses your list of pairs and calculates their sum.
def find_evens(n1, n2):
retlist = []
if n1 % 2 == 0: # n1 is even
print(n1)
elif n1+1 <= n2: # n1 is even
print(n1+1)
n1 = n1+2 # increment n1 by 2
if n1 <= n2:
find_evens(n1, n2) # call the same function recursively again with
new values
# Test the recursive functions.
print("evens between 2,10")
find_evens(2,10)
print("evens between 1,10")
find_evens(1,10)
print("evens between 1,11")
find_evens(1,11)
print("evens between 2,11")
find_evens(2,11)