Unit 7 : Python Function Flashcards

1
Q

List out the types of function ( 2 )

A
  1. Built-in functions provided by python ( input() , type() )
  2. Functions that we define ourselves and use
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What should we add when creating a function?

A
  1. Define a function using def keyword
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a function?

A
  1. Some reusable code that takes arguments as input does some computation and then returns a results or results
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we call / invoke the function ?

A
  1. By using function name, parenthesis and arguments in an expression
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What should we do when we are adding code to the function body?

A
  1. Indent the body
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Will the function be executed like this?
def print_lyrics():
print (“I’m a lumberjack, and I’m okay. “)

A
  1. No , it wasn’t called
  • A functions is a stored and reuse pattern
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is void functions also called as?

A
  1. Non-fruitful Functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a fruitful function?

A
  1. Functions that return value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Come out an example of the pesudocode of function

A

Start
Prompt user for N
Read N
Call AVRG(10,5,N)
End
Function AVRG(n1,n2,n3)
Calculate sum = n1 +n2 + n3
Calculate result = sum/3
Print result
EndFunction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the return statements do?

A
  1. Ends the function execution and “sends back” the result of the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Come out an example of the pesudocode of function ( with return value )

A

Start
Prompt user for N
Read N
Call AVRG(10,5,N) returning average
Print average
End
Function AVRG(n1,n2,n3)
Calculate sum = n1 +n2 + n3
Calculate result = sum/3
return result
EndFunction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an arguments?

A
  1. Is a value we pass into the fucntion as its input when we call the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When we put arguments?

A
  1. Put arguments in parenthesis after the name of the function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why should we use arguments?

A
  1. So that we can direct the function to do different kinds of work when we call it at different times

greet(“Hello”#This is arguments )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a parameter?

A
  1. A variable which we use in the function definition that is a “handle” that allowd the code in the function to access the arguments for a particular function invocation

def greet(message # This is parameter )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can we define more than one parameter in function ?

A
  1. Yes
17
Q

Do we need to match the number and order of arguments and parameters

A
  1. Yes
18
Q

What are function with return value ?

A
  1. Function that takes its arguments, do some computation and return a value to be used as the value of the function call in the calling expression
19
Q

What are the keywords used in functions that have return value?

A
  1. return