SlideShare a Scribd company logo
1 of 19
Download to read offline
Working with Functions
Intro, Understanding & Defining Functions
Parameters, Returning, Scope
Lectures by Harsh Sharma @ Apni Kaksha
Functions ( )
In large programs, we try to avoid a single large list of instructions.
It’s broken down into smaller units known as Functions.
A Function is a named unit of a group of program statements. This unit can
be invoked.
A Function is a subprogram/mini-program.
Function ki pehchaan
What is a Function?
When we know some things are repetitive or very similar.
To avoid writing same code again and again, we write it once and give it a
name.
This name is the function name, and whenever we call this name the code in
it will run.
Types of Functions
1. User Defined Functions : Designed by Programmers, like we will make.
2. Built-in Functions : Functions already present in python.
(pre-defined) e.g. input( ), len( ), int( ), etc.
3. Functions defined in : These are also predefined but in modules.
Modules To use them we have to import the corresponding
module/library.
e.g. factorial( ), sqrt( ), plot( ), etc.
Minimizing Repetitions
def greeting( ):
print(“Mere pyaare desh vaasiyon...”)
print(“....”)
print(“Mitrrooonnn!!!”)
greeting( )
Will run the three 3 statements.
#code_minimized.
When we have Similar Codes
print(‘Hello Passengers, this train will go to Delhi’)
print(‘Hello Passengers, this train will go to Lucknow’)
print(‘Hello Passengers, this train will go to Mumbai)
print(‘Hello Passengers, this train will go to Chandigarh’)
print(‘Hello Passengers, this train will go to Mars’)
def announcement(a) :
print(‘Hello Passengers, this train will go to’ ,a)
announcement(‘Delhi’)
announcement(‘Lucknow’)
announcement(‘Mumbai’)
announcement(‘Chandigarh’)
announcement(‘Mars’)
def sum(x, y) :
print(x+y)
Elements 0f a Function Definition
Function Header
Function Body
Keyword for
defining
parameters/arguments
Structure of a Python Program(not imp.)
def function1( ) :
:
def function2( ) :
:
#top level statements
statement1
statement2
:
Interpreter start _main_ se karta hai
Top to Bottom
Flow of Execution(learn the flow)
def fun( ) :
print(‘Hello’)
:
print(‘Babye’)
:
fun( )
:
:
Top to Bottom
Interpreter start _main_ se karta hai
Practice Time
Q1. w.a.p. to add two numbers using function. (using return)
Arguments : values being passed as arguments.
Parameters : values being received as arguments.
def multiply(x,y): parameters
return(x*y)
multiply(3,5) arguments
Arguments & Parameters
Arguments can be literals, variables, expressions.
But Parameters have to be some name/identifier, variable to hold incoming
values.
We can also call them :
Argument -> Actual Parameter or Actual Argument
Parameter-> Formal Parameter or Formal Argument
Arguments & Parameters
Passing Arguments
def calculate( a ,b ,c ):
:
calculate( 2, 4, 1 )
calculate( x, 8, 3 )
calculate( p, q, r )
calculate( 2, 1)
calculate( 5 )
*Positional arguments or Required arguments or Mandatory Arguments
Default Arguments
Sometimes we need passing arguments to be optional, i.e. if an argument is
passed we will use it and if not we will use the default value for that.
e.g. def food( main=‘Tinde’, sec=‘Parle-G’):
: : :
food(‘Paneer’, ‘Pulaao’)
food(‘Pasta’)
food( )
Important Rules for Default Parameters
Any parameter cannot have a default value unless all parameters appearing on
its right have default values.
def interest ( prin, time, rate = 0.15 ): ✔
def interest ( prin, time = 3, rate = 0.10 ):✔
def interest ( prin, time = 2, rate ): ❌
interest ( 3000, 5 )
interest ( 3000 )
Named Arguments
def interest ( prin, time, rate=0.15 ):
:
interest( rate=0.12, time=8, prin=1000 )
interest( time=5, rate=0.15, prin=2500 )
interest( time=5, prin=2500 )
interest( 1000, rate=0.12, time=4 )
Positional( required ) named
Some more rules
interest ( prin, time, rate=0.12 )
● As default parameters, named arguments also follow the rightmost
rule.
interest( prin=2000, 3, 0.15)
● No Multiple Values
interest( 2000, prin=1000,time=3.5 )
● No Parameter can be left empty
interest( prin=2000, rate=0.3 )
Practice Time
Q1. Find the output :
def interest( p , t=2, r = 0.10 ):
return (p*t*r)
print( interest(6100, 1) )
print( interest(5000, r = 0.05) )
print( interest(5000, 3, 0.12) )
print( interest(t=4, p=5000) )
Q2. What’s wrong with the code:
def add(a, b, c):
return a+b+c
print( “the answer is : ”, a+b+c )
Practice Time
Q. Find the output :
def change(P, Q = 30):
P = P + Q
Q = P - Q
print(P, ‘#’, Q)
return(P)
A = 150
B = 100
A = change( A, B)
print(A, ‘#’, B)
B = change(B)
Q. Find the output :
def fun(s):
k=len(s)
m=‘ ’
for i in range (0,k):
if(s[i].isupper( )):
m = m + s[i].lower( )
elif(s[i].isalpha( )):
m = m + s[i].upper( )
else :
m = m + ‘bb’
print(m)
fun(‘@gmail.com’)

More Related Content

Similar to Lecture 8.pdf

functioninpython-1.pptx
functioninpython-1.pptxfunctioninpython-1.pptx
functioninpython-1.pptxSulekhJangra
 
ch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdfch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdfzafar578075
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfDaddy84
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
Functions in python
Functions in pythonFunctions in python
Functions in pythoncolorsof
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxSahajShrimal1
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.pptjaba kumar
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
Python Learn Function with example programs
Python Learn Function with example programsPython Learn Function with example programs
Python Learn Function with example programsGeethaPanneer
 

Similar to Lecture 8.pdf (20)

functioninpython-1.pptx
functioninpython-1.pptxfunctioninpython-1.pptx
functioninpython-1.pptx
 
ch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdfch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdf
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
Lecture 08.pptx
Lecture 08.pptxLecture 08.pptx
Lecture 08.pptx
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Function
FunctionFunction
Function
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Python Learn Function with example programs
Python Learn Function with example programsPython Learn Function with example programs
Python Learn Function with example programs
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Lecture 8.pdf

  • 1. Working with Functions Intro, Understanding & Defining Functions Parameters, Returning, Scope Lectures by Harsh Sharma @ Apni Kaksha
  • 2. Functions ( ) In large programs, we try to avoid a single large list of instructions. It’s broken down into smaller units known as Functions. A Function is a named unit of a group of program statements. This unit can be invoked. A Function is a subprogram/mini-program. Function ki pehchaan
  • 3. What is a Function? When we know some things are repetitive or very similar. To avoid writing same code again and again, we write it once and give it a name. This name is the function name, and whenever we call this name the code in it will run.
  • 4. Types of Functions 1. User Defined Functions : Designed by Programmers, like we will make. 2. Built-in Functions : Functions already present in python. (pre-defined) e.g. input( ), len( ), int( ), etc. 3. Functions defined in : These are also predefined but in modules. Modules To use them we have to import the corresponding module/library. e.g. factorial( ), sqrt( ), plot( ), etc.
  • 5. Minimizing Repetitions def greeting( ): print(“Mere pyaare desh vaasiyon...”) print(“....”) print(“Mitrrooonnn!!!”) greeting( ) Will run the three 3 statements. #code_minimized.
  • 6. When we have Similar Codes print(‘Hello Passengers, this train will go to Delhi’) print(‘Hello Passengers, this train will go to Lucknow’) print(‘Hello Passengers, this train will go to Mumbai) print(‘Hello Passengers, this train will go to Chandigarh’) print(‘Hello Passengers, this train will go to Mars’) def announcement(a) : print(‘Hello Passengers, this train will go to’ ,a) announcement(‘Delhi’) announcement(‘Lucknow’) announcement(‘Mumbai’) announcement(‘Chandigarh’) announcement(‘Mars’)
  • 7. def sum(x, y) : print(x+y) Elements 0f a Function Definition Function Header Function Body Keyword for defining parameters/arguments
  • 8. Structure of a Python Program(not imp.) def function1( ) : : def function2( ) : : #top level statements statement1 statement2 : Interpreter start _main_ se karta hai Top to Bottom
  • 9. Flow of Execution(learn the flow) def fun( ) : print(‘Hello’) : print(‘Babye’) : fun( ) : : Top to Bottom Interpreter start _main_ se karta hai
  • 10. Practice Time Q1. w.a.p. to add two numbers using function. (using return)
  • 11. Arguments : values being passed as arguments. Parameters : values being received as arguments. def multiply(x,y): parameters return(x*y) multiply(3,5) arguments Arguments & Parameters
  • 12. Arguments can be literals, variables, expressions. But Parameters have to be some name/identifier, variable to hold incoming values. We can also call them : Argument -> Actual Parameter or Actual Argument Parameter-> Formal Parameter or Formal Argument Arguments & Parameters
  • 13. Passing Arguments def calculate( a ,b ,c ): : calculate( 2, 4, 1 ) calculate( x, 8, 3 ) calculate( p, q, r ) calculate( 2, 1) calculate( 5 ) *Positional arguments or Required arguments or Mandatory Arguments
  • 14. Default Arguments Sometimes we need passing arguments to be optional, i.e. if an argument is passed we will use it and if not we will use the default value for that. e.g. def food( main=‘Tinde’, sec=‘Parle-G’): : : : food(‘Paneer’, ‘Pulaao’) food(‘Pasta’) food( )
  • 15. Important Rules for Default Parameters Any parameter cannot have a default value unless all parameters appearing on its right have default values. def interest ( prin, time, rate = 0.15 ): ✔ def interest ( prin, time = 3, rate = 0.10 ):✔ def interest ( prin, time = 2, rate ): ❌ interest ( 3000, 5 ) interest ( 3000 )
  • 16. Named Arguments def interest ( prin, time, rate=0.15 ): : interest( rate=0.12, time=8, prin=1000 ) interest( time=5, rate=0.15, prin=2500 ) interest( time=5, prin=2500 ) interest( 1000, rate=0.12, time=4 ) Positional( required ) named
  • 17. Some more rules interest ( prin, time, rate=0.12 ) ● As default parameters, named arguments also follow the rightmost rule. interest( prin=2000, 3, 0.15) ● No Multiple Values interest( 2000, prin=1000,time=3.5 ) ● No Parameter can be left empty interest( prin=2000, rate=0.3 )
  • 18. Practice Time Q1. Find the output : def interest( p , t=2, r = 0.10 ): return (p*t*r) print( interest(6100, 1) ) print( interest(5000, r = 0.05) ) print( interest(5000, 3, 0.12) ) print( interest(t=4, p=5000) ) Q2. What’s wrong with the code: def add(a, b, c): return a+b+c print( “the answer is : ”, a+b+c )
  • 19. Practice Time Q. Find the output : def change(P, Q = 30): P = P + Q Q = P - Q print(P, ‘#’, Q) return(P) A = 150 B = 100 A = change( A, B) print(A, ‘#’, B) B = change(B) Q. Find the output : def fun(s): k=len(s) m=‘ ’ for i in range (0,k): if(s[i].isupper( )): m = m + s[i].lower( ) elif(s[i].isalpha( )): m = m + s[i].upper( ) else : m = m + ‘bb’ print(m) fun(‘@gmail.com’)