for i in range(5,10):
print(i)
factorial(n) = 123...(n-1)*n
def factorial1(n):
if n < 0:
return None
result = 1
for i in range(2,n+1):
result = result * i
return result
factorial1(10)
def factorial2(n):
if n < 0: # BASE CASE
return None
elif n <= 1: # BASE CASE
return 1
else:
return n*factorial2(n-1) # RECURSIVE CASE
factorial2(10)
def sum_list1(xs):
result = 0
for i in xs:
result = result + i
return result
sum_list1([20,10,30])
def sum_list2(xs):
if xs == []:
return 0
else:
return xs[0] + sum_list2(xs[1:])
sum_list2([20,10,30])