def add(a,b):
c=a+b
return(c)
d=add(3,4)
print(d)
def changelist(mylist):
mylist.extend([1,2,3,4])
return mylist
mylist=[10,20,30]
print("values inside before function call:",mylist)
changelist(mylist)
print("values after function call:",mylist)
def printinfo(name,age):
print("Name:",name)
print("Age",age)
return
#now calling printinfofunction
printinfo(age=50,name="mikki")
printinfo(10,"mikki")
'''default argument demo'''
"""def printinffo(name='john',age=35):
print("Name:",name)print("Age", age)
return
printinffo(age=50,name="mikki")
printinffo(name="harry")
printinffo()
printinfo """
def printinnfo(arg1,*vartuple):
print("output is:")
print(arg1)
print(sum(vartuple))
print (vartuple)
for var in vartuple:
print(var)
return
#now calling printinfo Function
printinnfo(10)
printinnfo(20,77,58,42,21,5)
def printinnfo(*vartuple):
print(sum(vartuple))
print (vartuple)
for var in vartuple:
print(var)
return
#now calling printinfo Function
printinnfo(10)
printinnfo(20,77,58,42,21,5)
def add(x,y):
return x+y
def sub(x,y):
return x-y
def mul(x,y):
return x*y
"""def div (x,y):
return x/y
print("select option")
print("1.add")
print("2.sub")
print("3.mul")
print("4.div")
choice=input("enter choice(1/2/3/4):")
num1=int(input("enter first number:"))
num2=int(input("enter second number:"))
if choice=="1":
print(num1,"+",num2,"=",add(num1,num2))
elif choice=="2":
print(num1,"-",num2,"=",sub(num1,num2))
elif choice=="3":
print(num1,"*",num2,"=",mul(num1,num2))
elif choice=="4":
print(num1,"/",num2,"=",div(num1,num2))
else:
print("invalid input:")"""
"""total=0
def sum(arg1,arg2):
global total
total=arg1+arg2
print("inside the function:",total)
return total
sum(20,30)
print("outside the function global total:",total)"""
def fact(n):
if n=1:
return 1
else:
return n*fact(n-1)
a=int(input("enter a number:"))
print(fact(a))
def factorial(n):
for i in range(n):
a=a*i
a-=1
return a
s=int(input("enter the number:"))
print(factorial(s))
No comments:
Post a Comment