Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
37 views3 pages

## Split The Operation Into Multiple Block: Print Input Len

The document discusses function recursion in Python. It provides examples of a recursive function called f1 that takes a parameter and recursively calls itself, each time decrementing the parameter value. The output of each recursive call is printed to demonstrate how recursion is used to calculate the final output.

Uploaded by

Arun Mmohanty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

## Split The Operation Into Multiple Block: Print Input Len

The document discusses function recursion in Python. It provides examples of a recursive function called f1 that takes a parameter and recursively calls itself, each time decrementing the parameter value. The output of each recursive call is printed to demonstrate how recursion is used to calculate the final output.

Uploaded by

Arun Mmohanty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

6/20/2020 Untitled86 - Jupyter Notebook

In [ ]: What is Fuction

Group of statements or block or collection of statement , we can call or re-u


Outside program as module.

1. usages: code reusaability


2. east to understand ## split the operation into multiple block

procrdure language term


print()
input()
len() etc

subroutine ==> user defined function


method ==> in oops(function,subroutine)
e.g. display() ## subroutine function
object.diplay() ## method

what is module:
1. python souce file
2. reusability
3. overloading

In [17]: #function recursion


def f1(var): ##5
if(var>0): ##True
result = var+f1(var-1) ## result=5+f1(5-1) ## 5+f1(4) ##5+10=15
print(result) #15
else:
result=0
print(result)
return result

f1(5)

0
1
3
6
10
15

Out[17]: 15

localhost:8888/notebooks/Untitled86.ipynb?kernel_name=python3 1/3
6/20/2020 Untitled86 - Jupyter Notebook

In [8]: #5+f1(4)
def f1(var): ##4
if(var>0): ##True
result = var+f1(var-1) ## result=4+f1(4-1) ## 4+f1(3)##4+6=10
print(result) ##10
else:
result=0
return result

f1(4)

1
3
6
10

Out[8]: 10

In [10]: #4+f1(3)
def f1(var): ##3
if(var>0): ##True
result = var+f1(var-1) ## result=3+f1(3-1) ## 3+f1(2)##3+3
print(result) #6
else:
result=0
return result
f1(3)

1
3
6

Out[10]: 6

In [12]: #3+f1(2)
def f1(var): ##2
if(var>0): ##True
result = var+f1(var-1) ## result=2+f1(2-1) ## 2+f1(1)##2+1=3
print(result) ##3
else:
result=0
return result
f1(2)

1
3

Out[12]: 3

localhost:8888/notebooks/Untitled86.ipynb?kernel_name=python3 2/3
6/20/2020 Untitled86 - Jupyter Notebook

In [13]: #2+f1(1)
def f1(var): ##1
if(var>0): ##True
result = var+f1(var-1) ## result=1+f1(1-1) ## 1+f1(0) ##1+0=1
print(result) ##1
else:
result=0
return result
f1(1)

Out[13]: 1

In [14]: #Result from last fun# 1+f1(0) ==> 1+0=1


def f1(var): ##0
if(var>0): ##False
result = var+f1(var-1)
print(result)
else:
result=0
return result
f1(0)

Out[14]: 0

In [ ]: 1+0=1

localhost:8888/notebooks/Untitled86.ipynb?kernel_name=python3 3/3

You might also like