I am currently trying to learn how to use define functions using python and I am
ID: 3667863 • Letter: I
Question
I am currently trying to learn how to use define functions using python and I am confused on what "return" does in code.
for example in lecture there were two different examples:
example 1)
def fun(a):
return a+2
x=fun(2)*fun(3)
what is the value of x?
a) 9
b) 4
c) 16
d) none of the above
example 2)
def fun(a,b):
c=((a+” “)*len(b)).title()
return c
x=fun(“ab”,”caa”)
What is the value of x?
Can you please explain what the return does and how the answer in number two differs from one which would be
def fun(a,b):
c=((a+” “)*len(b)).title()
x=fun(“ab”,”caa”)
thanks!
Explanation / Answer
example 1.
def fun(a):
return a+2
x=fun(2)*fun(3)
what is the value of x?
Ans. (d) none of the above (20)
example 2)
def fun(a,b):
c=((a+” “)*len(b)).title()
return c
x=fun(“ab”,”caa”)
What is the value of x?
Ans. 'Ab Ab Ab'
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.