Computer science Solutions term 1 || Objective Type Questions MCQS || Objective Answers Class 12 Solution || Computer Science ||
1. A function in Python begins with which keyword?
(a) void
(b) return
(c) int
(d) def
Ans: (d) def
2. Name the statement that sends back a value from a function.
(a) print
(b) input
(c) return
(d) None
Ans: (c) return
3. Functions that do not return any value are known as:
(a) fruitful functions
(b) void functions
(c) library functions
(d) user-defined functions
Ans: (b) void functions
4. A variable created or defined within a function body is classified as:
(a) local
(b) global
(c) built-in
(d) instance
Ans: (a) local
5. Which of the following arguments works with implicit values that are used if no value is provided?
(a) keyword
(b) required
(c) variable-length
(d) default
Ans: (d) default
6. Which values are used by the functions to communicate information back to the caller?
(a) local
(b) global
(c) return
(d) random
Ans: (c) return
7. What is the output of the program given below?
x = 50
def func (x) :
x = 2
func (x)
print ('x is now', x)
(a) x is now 50
(b) x is now 2
(c) x is now 100
(d) Error
Ans: (a) x is now 50
8. Which is the most appropriate definition for recursion?
(a) A function that calls itself
(b) A function execution instance that calls another execution instance of the same function
(c) A class method that calls another class method
(d) An in-built method that is automatically called
Ans: (b) A function execution instance that calls another execution instance of the same function
9. Fill in the line of code for calculating the factorial of a number:
def fact (num):
if num == 0 :
return 1
else:
return
(a) num*fact(num-1)
(b) (num-1)*(num-2)
(c) num*(num-1)
(d) fact(num)*fact(num-1)
Ans: (a) num*fact(num-1)
10. Which of the following statements is false about recursion?
(a) Every recursive function must have a base case.
(b) Infinite recursion can occur if the base case isn't properly mentioned.
(c) A recursive function makes the code easier to understand.
(d) Every recursive function must have a return value.
Ans: (d) Every recursive function must have a return value.
11. What is the output of the following snippet?
def fun (n):
if (n > 100):
return n - 5
return fun (fun (n+11))
print (fun (45))
(a) 50
(b) 100
(c) 74
(d) Infinite loop
Ans: (b) 100
12. What happens if the base condition isn't defined in recursive programs?
(a) Program gets into an infinite loop
(b) Program runs once
(c) Program runs n number of times, where n is the argument given to the function
(d) An exception is thrown
Ans: (a) Program gets into an infinite loop
13. What is the default return value for a function that does not return any value explicitly?
(a) None
(b) int
(c) double
(d) null
Ans: (a) None
14. 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
Ans: (b) both function name and parameter list
15. Which of the following keywords marks the beginning of the function block?
(a) func
(b) define
(c) def
(d) function
Ans: (c) def
16. What is the name given to that area of memory, where the system stores the parameters and local
variables of a function call?
(a) a heap
(b) storage area
(c) a stack
(d) an array
Ans: (c) a stack
17. 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
Ans: (d) return number
18. 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):
Ans: (c) def f(a = 1, b = 1, c = 2):
19. Which of the following statements is not true for parameter passing to functions?
(a) You can pass positional arguments in any order.
(b) You can pass keyword arguments in any order.
(c) You can call a function with positional and keyword arguments.
(d) Positional arguments must be before keyword arguments in a function call.
Ans: (a) You can pass positional arguments in any order
20. Which of the following function calls can be used to invoke the below function definition?
def test(a, b, c, d)
(a) test(1, 2, 3, 4)
(b) test(a = 1, 2, 3, 4)
(c) test(a = 1, b = 2, c = 3, 4)
(d) test(a = 1, b = 2, c = 3, d = 4)
Ans: (a) test(1, 2, 3, 4),
(d) test(a = 1, b = 2, c = 3, d = 4)
21. 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)
(b) test(a = 1, 2, 3, 4)
(c) test(a = 1, b = 2, c = 3, 4)
(d) test(a = 1, b = 2, c = 3, d = 4)
Ans: (b) test(a = 1, 2, 3, 4)
(c) test(a = 1, b = 2, c = 3, 4)
22. What is a variable defined outside all the functions referred to as?
(a) A static variable
(b) A global variable
(c) A local variable
(d) An automatic variable
Ans: (b) A global variable
23. What is a variable defined inside a function referred to as
(a) A static variable
(b) A global variable
(c) A local variable
(d) An automatic variable
Ans: (c) A local variable
24. Carefully observe the code and give the answer.
def function1(a):
a= a + '1'
a = a * 2
>>> function1("hello")
(a) indentation Error
(b) cannot perform mathematical operation on strings
(c) hello2
(d) hello2hello2
Ans: (a) indentation Error
25. What is the result of this code?
def print_double(x):
print(2 ** x)
print_double(3)
(a) 8
(b) 6
(c) 4
(d) 10
Ans: (a) 8
Comments
Post a Comment