For all the parts of this question you must not sort nor reverse a list You must
ID: 3892391 • Letter: F
Question
For all the parts of this question you must not sort nor reverse a list You must not use loops nor abstract list functions. You may use recursion though. All five parts should be submitted in one file and should include design recipe for each part as well.
Part a) Write a Python function create_odds that consumes a natural number (target) and returns a list of all positive odd integers that are <= target in ascending order.
For example: • create_odds(8) => [1, 3, 5, 7] • create_odds(0) => []
Explanation / Answer
Hi Student,
Find the code below :
def create_odds(x,xx=[]):
if x>0:
create_odds(x-1)
if x & 1:
xx.append(x)
return xx
num = 8
print create_odds(num)
Happy Learning :)