19.2k views
0 votes
Write a recirsive function named productsof odds that accepts a tuple

User Gaege
by
3.1k points

1 Answer

3 votes

Answer:

def productOfOdds(t):

if len(t) == 1:

if t[0] % 2 == 1:

return t[0]

else:

return 1

else:

if t[0] % 2 == 1:

return t[0] * productOfOdds(t[1:])

else:

return productOfOdds(t[1:])

t = (1, 2, 3, 4, 5, 6, 7, 8, 9)

print("Product of odd elements:", productOfOdds(t)

User John Elemans
by
4.0k points