function Flashcards
return a,b
is it correct or is it gives error
correct
it returns multiple value i.e. a and b
when recursive call is made then ____________ will be created in _________________
when recursive call is made then activation record will be created in stack
Syntax to create user defined functions
def function_name(parameters):
statement1
statement2
:
return value
give example of tail recursion
def tail_rec(n):
if n==0:
return
else:
print(n)
return tail_rec(n-1)
tail_rec(4)
tail recursion
In the program the very last statement is the only one recursive call and there is no other statement after that then it is called as tail recursion
non-tail recursion
in the program after the recursive call some statements to execute, then it is called non-tail recursion
recursion
function calling itself is called recursion
tell the error
def summation(a,b):
summation = a+b
return a,b
no error
Function calling itself is called __________
recursion
is ‘def’ required to create function
yes, required
def wish():
print(‘Good evening’)
print(‘hey we are in function’)
for i in range(3):
wish()
Good evening
hey we are in function
Good evening
hey we are in function
Good evening
hey we are in function
if recursion doesn’t have termination condition, it will leads to _______________________
stack overflow
types of functions
1.)Built-in functions
2.)User defined functions
Recursion function should have _____________ condition
termination or base
how can we write equivalent non recursive program of tail recursion
by using loops