0% found this document useful (0 votes)
10 views5 pages

Function Assignment-1

The document contains a series of questions and assertions related to function assignments in Python, covering topics such as return values, function headers, variable scope, and parameter types. It includes multiple-choice questions, error identification in code snippets, and application-based questions requiring code corrections and predictions of outputs. The content is structured to test knowledge of Python functions and their behavior.

Uploaded by

Parth Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Function Assignment-1

The document contains a series of questions and assertions related to function assignments in Python, covering topics such as return values, function headers, variable scope, and parameter types. It includes multiple-choice questions, error identification in code snippets, and application-based questions requiring code corrections and predictions of outputs. The content is structured to test knowledge of Python functions and their behavior.

Uploaded by

Parth Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CHAPTER- FUNCTION ASSIGNMENT

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

5. Which of the following items are present in the function header ?


a) function name only
b) both function name and parameter list
c) parameter list only
d) return value
6. Pick one the following statements to correctly complete the function body in the given code snippet.

def f(number):
#Missing function body
print(f(5))

a) return "number" b) print(number) c) print("number") d) return


number
7. Which of the following function headers is correct ?
a) def f(a = 1, b):
b) def f(a = 1, b, c = 2):
c) def f(a = 1, b = 1, c = 2):
d) def f(a = 1, b = 1, c = 2, d):
8. Which of the following is not correct in context of Positional and Default parameters in Python
functions ?

a) Default parameters must occur to the right of Positional parameters.


b) Positional parameters must occur to the right of Default parameters.
c) Positional parameters must occur to the left of Default parameters.
d) All parameters to the right of a Default parameter must also have Default values.

1
9. Which of the following is not correct in context of scope of variables ?

a) Global keyword is used to change value of a global variable in a local scope.


b) Local keyword is used to change value of a local variable in a global scope.
c) Global variables can be accessed without using the global keyword in a local scope.
d) Local variables cannot be used outside its scope

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)

11. What is a variable defined outside all the functions referred to as ?

a) A static variable c) A global variable


b) A local variable d) An automatic variable

12. What is a variable defined inside a function referred to as

a) A static variable c) A global variable


b) A local variable d) An automatic variable

13. Which of the given argument types can be skipped from a function call ?

a) positional arguments c) keyword arguments


b) named arguments d) default arguments

Assertions and Reasons


14. Assertion. A function is a subprogram.
Reason. A function exists within a program and works within it when called.
15. Assertion. Non-default arguments cannot follow default arguments in a function call.
Reason. A function call can have different types of arguments.
16. Assertion. A variable declared inside a function cannot be used outside it.
Reason. A variable created inside a function has a function scope.

Application Based Questions

17. Write the term suitable for following descriptions :


(a) A name inside the parentheses of a function header that can receive a value.
(b) An argument passed to a specific parameter using the parameter name.
(c) A value passed to a function parameter.
(d) A value assigned to a parameter name in the function header.
(e) A value assigned to a parameter name in the function call.
(f) A name defined outside all function definitions.
(g) A variable created inside a function body.

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 :

def Call(P = 40, Q = 20):


P=P+Q
Q=P-Q
print(P, '@', Q)
return P
R = 200
S = 100
R = Call(R, S)
print(R, '@', S)
S = Call(S)
print(R, '@', S)

20. Consider the following code and write the flow of execution for this. Line numbers have been given for your
reference.

1. def power(b, p):


2. y = b ** p
3. return y
4.
5. def calcSquare(x):
6. a = power(x, 2)
7. return a
8.
9. n = 5
10. result = calcSquare(n)
11. print(result)

21. What will be the output of following program ?

num = 1
def myfunc():
global num
num = 10
return num
print(num)
print(myfunc())
print(num)

22. Predict the output of the following code :

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)

23. What is wrong with the following function definition ?

def addEm(x, y, z):


return x + y + z
print("the answer is", x + y + z)

24. Consider the code below and answer the questions that follow :

def multiply(number1, number2):


answer = number1 * number2
print(number1, 'times', number2, '=', answer)
return(answer)
output = multiply(5, 5)

(i) When the code above is executed, what prints out ?

(ii) What is variable output equal to after the code is executed ?

25. Find the errors in code given below :

def minus(total, decrement)


output = total - decrement
print(output)
return (output)

26. Find the errors in code given below :

def alpha (n, string = 'xyz', k = 10) :


return beta(string)
return n

def beta (string)


return string == str(n)

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:

1. def sum(a, b, c, d):


2. result = 0
3. result = result + a + b + c + d
4
4. return result
5.
6. def length():
7. return 4
8.
9. def mean(a, b, c, d):
10. return float(sum(a, b, c, d))/length()
11.
12.print(sum(a, b, c, d), length(), mean(a, b, c, d))

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.

You might also like