Function Assignment-1
Function Assignment-1
1. If return statement is not used inside the function, the function will return:
a) 0
b) None object
c) an arbitrary integer
d) Error! Functions in Python must have a return statement
2. Which of the following keywords marks the beginning of the function block?
a) func c) define
b) def d) function
3. What is the area of memory called, which stores the parameters and local variables of a function call ?
a) a heap b) storage area c) a stack d)an array
4. Find the errors in following function definitions :
a) def main()
print ("hello")
b) def func2():
print(2 + 3)
c) def compute():
print (x * x)
d) square (a)
return a * a
def f(number):
#Missing function body
print(f(5))
1
9. Which of the following is not correct in context of scope of variables ?
10. Which of the following function calls will cause Error while invoking the below function definition ?
def test(a, b, c, d)
a) test(1, 2, 3, 4) c) test(a = 1, 2, 3, 4)
b) test(a = 1, b = 2, c = 3, 4) d) test(a = 1, b = 2, c = 3, d = 4)
13. Which of the given argument types can be skipped from a function call ?
18. What are the errors in following codes ? Correct the code and predict output :
total = 0;
def sum(arg1, arg2):
2
total = arg1 + arg2;
print("Total :", total)
return total;
sum(10, 20);
print("Total :", total)
19. Find and write the output of the following python code :
20. Consider the following code and write the flow of execution for this. Line numbers have been given for your
reference.
num = 1
def myfunc():
global num
num = 10
return num
print(num)
print(myfunc())
print(num)
a = 10
y=5
def myfunc():
y=a
3
a=2
print("y =", y, "a =", a)
print("a + y =", a + y)
return a + y
print("y =", y, "a =", a)
print(myfunc())
print("y =", y, "a =", a)
24. Consider the code below and answer the questions that follow :
print(alpha("Valentine's Day"):)
print(beta(string = 'true'))
print(alpha(n = 5, "Good-bye"):)
27. Draw flow of execution and also write the output of given program:
28. Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount
converted to rupees. Create the function in both void and non-void forms.