We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
914723, 1105 AM
In]:
In
In
In
In
(1):
[2]:
[3]:
[6]:
Unitled170 - Jupyter Notebook
M #functions
#is a block of code which performs specific task
two steps
#1)function declare and define
#2)calling function
#Two type of function
#l)user define
#2)Builtup functions
atwo types
#call by value/argument
fcall by refrence->Recursion
M #user define functions
def display():#function create and define
print("This is function")
display()éfunction call
This is function
» display()
This is function
M def star():
print ("***theseeeeeneeeny
star()
M star()
display()
star()
This is function
localhost 8889inotebooks/Untiled70pynb7kerel_name=python3
us914723, 1105 AM Unitled170 - Jupyter Notebook
In [10]: W for i in range(1,11):
star()
display()
star()
SS
fs ein
rs cin
fs te gin
mas te ec
tas ts gi
tas gc
SES
SS
This is function
In [11]: M def add(a,b):
print (a+b)
add(23,4)
27
In [12]: MW add¢4,6)
10
In [15]: MW def add(a,b,c):
print (a+b+c)
add(23,4,7)
34
localhost 8889Inotebooks/Untiled170.pynb ke
name=pythor3 218914723, 1105 AM
In [16]: W add(3,3,3)
add(5,7,7)
9
19
In [17]: W def add():
a=10
b=20
print (a+b)
add()
30
In [18]: def add():
Unitled170 - Jupyter Notebook
azint(input("Enter any number for a"))
b=int(input("ENter for b"))
print(a+b)
add()
Enter any number for
ENter for
8
ba
In [19]: W for i in range(1,5)
add()
Enter any
ENter for
7
Enter any
ENter for
7
Enter any
ENter for
121
Enter any
ENter for
95,
localhost 8889Inotebooks/Untiled170.pynb ke
number
ba
number
33
number
bss,
number
b7
for
for
for
for
aa
a3
ass
age
name=pythor3
as914723, 1105 AM
In [20]:
In [23]:
In [ ]:
localhost 8889Inotebooks/Untiled170.pynb ke
W
W
Unitled170 - Jupyter Notebook
def add(
a=int(input("Enter any number for a"))
beint(input("ENter for b"))
print("sum=",a+b)
def sub(
azint(input("Enter any number for a"))
beint(input("ENter for b"))
print("sub=",a-b)
def mul():
azint(input("Enter any number for a"))
beint(input("ENter for b"))
print(*mul=",a*b)
def div(
azint(input ("Enter any number for a"))
beint(input("ENter for b"))
print(*div=",a/b)
add()
sub()
mul()
div()
Enter any number for aS
ENter for b6
sume 11
Enter any number for a45
ENter for b3
sub= 42
Enter any number for a5
ENter for b6
mul= 30
Enter any number for a67
ENter for b2
divs 33.5
def nunbercheck(a):
iF (ana:
print("Even")
else:
print("odd")
numbercheck(6)
numbercheck(5)
Even
odd
Recursion function
#its calling itself
def hello():
print("Hello")
hello()
hello()
5 name=pythond
46914723, 1105 AM Unitled170 - Jupyter Notebook
In [1]: M import sys
print(sys.getrecursionlimit())
3000
In [2]: MW #factorial of number
#5*4*3*241-126
fact=1
for i in range(5,1,-1):
fact=fact*i
print (fact)
128
In [6]: W #5*4*3*2*1=120
def factorial(a):
fact=1
for a in range(a,1,~1):
fact=fact*a
print (fact)
factorial(7)
5040
In [7]: W def fact(n): 5
if ns=1:
return 1
else:
return n*fact(n-1)
fact(5)
out[7]: 120
In [9]: M a=int(input("ENter a"))
result=fact(a)
print(result)
ENter a6
728
Inf]: W
localhost 8889inotebooks/Untiled70pynb7kerel_name=python3