- Iterative product of 2 natural numbers
def product_iter(a, b): # iteration product
'''consider all natural numbers'''
if b == 0:
return b
for i in range(b):
if i == b - 1:
return a
return a + product_iter(a, b - 1)
product_iter(5, 1)
- Recursive product of 2 natural numbers
def product_recur(a, b): # recursive product
'''consider all natural numbers'''
if b == 0:
return b
if b == 1:
return a
return a + product_recur(a, b - 1)
product_recur(5, 1)