Functions
# def greet(name):
# print("Good morning, " + name)
# def mySum(num1, num2):
# return num1 + num2
# greet("Onam")
# s = mySum(76, 4)
# print(s)
def greet(name ="Stranger"):
print("Good morning, " + name)
greet()
'''
def percent (marks):
return (sum(marks)/400)*100
marks1 = [10, 10, 10, 10]
percentage1 = percent(marks1)
marks2 = [75, 98, 88, 78]
percentage2 = percent(marks2)
print(percentage1, percentage2)
'''
Recursion
# n! = 1*2*3*4*5*...(n-1)*n
#
# n = 0
# product = 1
# for i in range(n):
# product = product * (i+1)
# print(product)
'''
def factorial_iter(n):
product = 1
for i in range(n):
product = product * (i+1)
return product
print(factorial_iter(4))
'''
def factorial_recursive(n):
if n ==1 or n ==0:
return 1
return n * factorial_recursive (n-1)
f = factorial_recursive(4)
print(f)
Comments
Post a Comment