This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 5 Functions In Python – Quiz 6 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 5 Functions In Python Quiz 6 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which of these statements about a function is correct? A) A function runs only when it is called. B) A function runs automatically every time we open Python. C) A function is just a variable. D) A function is a number. Show Answer Correct Answer: A) A function runs only when it is called. 2. What is the default behavior of the sort() method? A) Does not sort the list. B) Sorts based on the length of elements. C) Sorts in descending order. D) Sorts in ascending order. Show Answer Correct Answer: D) Sorts in ascending order. 3. Def Fun ..... love(a, 20):print(a+20)is A) Will print 20 added to value of a. B) Correct. C) Incorrect. D) Has Syntax error. Show Answer Correct Answer: D) Has Syntax error. 4. How can you use a lambda function to sort a list of tuples by the second element? A) 'sorted(list of tuples, key=lambda x:x[2])'. B) 'sorted(list of tuples, key=lambda x:x[1])'. C) 'sorted(list of tuples, key=lambda x:x[-1])'. D) 'sorted(list of tuples, key=lambda x:x[0])'. Show Answer Correct Answer: B) 'sorted(list of tuples, key=lambda x:x[1])'. 5. If the return statement is not used in the function then which type of value will be returned by the function? A) Int. B) Str. C) Float. D) None. Show Answer Correct Answer: D) None. 6. Which operator is used to check if a value exists in a sequence? A) Has. B) Exists. C) In. D) Contains. Show Answer Correct Answer: C) In. 7. Which of the following cannot be converted in a recursion function? A) Factorial program. B) Random function generation. C) Binary search. D) Greatest common divisor(GCD). Show Answer Correct Answer: B) Random function generation. 8. The default value for a parameter is defined in function ..... ? A) Definition. B) Return statement. C) Header. D) None of the above. Show Answer Correct Answer: C) Header. 9. Which statement is correct to import all modules from the package A) From package import all. B) From package import *. C) From package include all. D) From package include *. Show Answer Correct Answer: B) From package import *. 10. How do you print 'Hello' five times using a for loop? A) Print('Hello' * 5). B) For i in range(0, 6, 2):print('Hello'). C) For i in range(5):print('Hello'). D) Print('Hello' + 'Hello' + 'Hello' + 'Hello' + 'Hello'). Show Answer Correct Answer: C) For i in range(5):print('Hello'). 11. Assertion (A):Built in function are predefined in the language that are used directly. Reason (R):print() and input() are built in functions. A) Both A and R are true and R is the correct explanation for A. B) Both A and R are true and R is not correct explanation for A. C) A is true but R is false. D) A is false but R is true. Show Answer Correct Answer: B) Both A and R are true and R is not correct explanation for A. 12. What does the append() method do in Python lists? A) Inserts an element at a specific position. B) Returns the last element of the list. C) Removes an element from the list. D) Adds an element to the end of the list. Show Answer Correct Answer: D) Adds an element to the end of the list. 13. Parameters are the (a) used in the function definition. A) A. variables. B) Values. C) Constant. D) Method. Show Answer Correct Answer: A) A. variables. 14. What will be the output of the following code? "'pythondef square(x):return x * xresult = square(3)print(result) "' A) '9'. B) '6'. C) '3'. D) 'None'. Show Answer Correct Answer: A) '9'. 15. Which of the following is TRUE about procedures in Python? A) Procedures are functions that do not return a value. B) Procedures must always return a value. C) Procedures cannot have parameters. D) Procedures are not allowed in Python. Show Answer Correct Answer: A) Procedures are functions that do not return a value. 16. What will be the output of the following code? "'pythondef multiply(x, y=2):return x * yresult = multiply(5)print(result) "' A) '10'. B) 'Error'. C) '2'. D) '5'. Show Answer Correct Answer: A) '10'. 17. Which of the following statements about return statements is FALSE? A) A function can have multiple return statements. B) A function must always return a value. C) A function can return more than one value as a tuple. D) A function can return 'None'. Show Answer Correct Answer: B) A function must always return a value. 18. Which keyword is used to return a value from a function in Python? A) 'return'. B) 'output'. C) 'yield'. D) 'give'. Show Answer Correct Answer: A) 'return'. 19. What is the output of the following code? def add():x, y = 4, 7; print('Sum:', x + y); add() A) Sum:11. B) Sum:4. C) Sum:7. D) Error. Show Answer Correct Answer: A) Sum:11. 20. How can you specify a default value for a function parameter in Python? A) 'def myFunction(param <-5):'. B) 'def myFunction(param:5):'. C) 'def myFunction(param=5):'. D) 'def myFunction(param $\rightarrow$ 5):'. Show Answer Correct Answer: C) 'def myFunction(param=5):'. 21. What is a function in programming? A) A group of statements that perform a specific task. B) A type of variable. C) A method of debugging. D) A way to store data. Show Answer Correct Answer: A) A group of statements that perform a specific task. 22. Leo wants to create a function that will roll a dice. Which is the correct function definition header? A) Def diceroll []:. B) Def diceroll (). C) Def diceroll ():. D) Def dice roll ():. Show Answer Correct Answer: C) Def diceroll ():. 23. Which of the following statements is FALSE about local and global variables? A) Local variables are created when a function starts and destroyed when it ends. B) Global variables exist throughout the lifetime of the programme. C) Local variables can be accessed outside their function. D) Global variables can be accessed inside functions unless shadowed. Show Answer Correct Answer: C) Local variables can be accessed outside their function. 24. Which of the following is an example of a keyword argument? A) My func(12). B) My func(name='Reema', age=12). C) My func(12, 'Reema'). D) My func('Reema', 12). Show Answer Correct Answer: B) My func(name='Reema', age=12). 25. A function is said to be ..... if it calls itself A) Built function. B) Pre defined function. C) Recursive function. D) None of the above. Show Answer Correct Answer: C) Recursive function. 26. Which of the following is a valid lambda function in Python? A) 'lambda(x, y) { x + y }'. B) 'lambda x, y:x + y'. C) 'lambda(x, y):x + y'. D) 'lambda x, y { x + y }'. Show Answer Correct Answer: B) 'lambda x, y:x + y'. 27. What is the default starting value of the range() function? A) 1. B) It depends on the input. C) 0. D) None. Show Answer Correct Answer: C) 0. 28. What is a parameter in a function? A) A piece of data sent into a function. B) A variable that holds the return value. C) A type of function. D) None of the above. Show Answer Correct Answer: A) A piece of data sent into a function. 29. Which of the following is a valid way to return multiple values from a function in Python? A) 'return a, b'. B) 'return [a, b]'. C) 'return {a, b}'. D) 'return (a, b)'. Show Answer Correct Answer: A) 'return a, b'. 30. The values received in the function definition/header statement are called ..... A) Arguments. B) Parameter. C) Values. D) None. Show Answer Correct Answer: B) Parameter. 31. Which of the following keyword is used to define the function testpython(): A) Define. B) Whle. C) Def. D) Pass. Show Answer Correct Answer: C) Def. 32. There are predefined functions that are available in a module. For using them we need to import the module. A) Function defined in module. B) Built-in functions. C) User defined functions. D) Predefined functions. Show Answer Correct Answer: A) Function defined in module. 33. What is the output of the following code? "'pythondef f(x):return x**2print(f(5)) "' A) '5'. B) '25'. C) 'x**2'. D) '10'. Show Answer Correct Answer: B) '25'. 34. Study the following program and select the possible output:import randomX = random.random()Y = random.randint(0, 4)print(int(X), ":", Y + int(X)) A) 1:6. B) 2:4. C) 0:3. D) -1:0. Show Answer Correct Answer: C) 0:3. 35. If a function returns a value, it should generally be called from A) Main( ). B) An expression. C) A different program. D) A cellphone. Show Answer Correct Answer: B) An expression. 36. What are the two main types of functions? A) Custom function. B) Built-in function & User defined function. C) System function. D) User function. Show Answer Correct Answer: B) Built-in function & User defined function. 37. Value returning functions should be generally called from inside of an expression. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 38. What is the output of the function call print(greet('Alice'))? A) Hello, Guest. B) Hello, John. C) Hello, 22. D) Hello, Alice. Show Answer Correct Answer: D) Hello, Alice. 39. How do you reverse a string in Python? A) String.reverse(). B) Reverse(string). C) String.flip(). D) String[::-1]. Show Answer Correct Answer: D) String[::-1]. 40. What is the 'return' statement used for in a function? A) To print a value to the console. B) To define a new variable. C) To exit a function and return a value to the caller. D) To loop through a list of elements. Show Answer Correct Answer: C) To exit a function and return a value to the caller. 41. A recursive function is A) A function that calls other functions in a recursive way. B) Any function that calls itself is called recursive. C) A function that has a base case or termination condition. D) None of the above. Show Answer Correct Answer: B) Any function that calls itself is called recursive. 42. What will be the output of the following code? "'pythondef multiply(x, y):product = x * y return productprint(multiply(2, 5)) "' A) '10'. B) '25'. C) '7'. D) 'None'. Show Answer Correct Answer: A) '10'. 43. Which of the following is a common use case for lambda functions? A) Writing complex algorithms. B) Defining a new class. C) Passing a simple function as an argument. D) Creating a new module. Show Answer Correct Answer: C) Passing a simple function as an argument. 44. What will be the output of this program?def addOne(number):number += 1 return numberone = addOne(0)two = addOne(one)print(two) A) 0. B) 3. C) 2. D) 1. E) 4. Show Answer Correct Answer: C) 2. 45. What will be the output of the following Python code?def cube(x):return x * x * xx = cube(3)print (x) A) 9. B) 3. C) 30. D) 27. Show Answer Correct Answer: D) 27. 46. What is the purpose of the 'return' statement in a Python function? A) To print the result. B) To exit the function and return a value. C) To define a new function. D) To repeat the function. Show Answer Correct Answer: B) To exit the function and return a value. 47. What is the output of the following code? def first ..... five ..... even ..... numbers():for num in range(2, 11):if num % 2 == 0:print(num); first ..... five ..... even ..... numbers() A) 2, 4, 6, 8, 10. B) None. C) 1, 2, 3, 4, 5. D) Error. Show Answer Correct Answer: A) 2, 4, 6, 8, 10. 48. The ..... keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later. A) Pass. B) Execute. C) Pause. D) Skip. Show Answer Correct Answer: A) Pass. 49. Assertion (A):Keyword arguments are related to the function calls. Reason (R):When you use keyword arguments in a function call, the caller identifies the arguments by the parameter name. A) Both A and R are true and R is the correct explanation for A. B) Both A and R are true and R is not correct explanation for A. C) A is true but R is false. D) A is false but R is true. Show Answer Correct Answer: A) Both A and R are true and R is the correct explanation for A. 50. A group of statements that exist within a program for the purpose of performing a specific task is a(n) ..... A) Function. B) Variable. C) Loop. D) Block. Show Answer Correct Answer: A) Function. 51. Which of the following is the correct way to call a function named 'hello' with one argument, '"World"'? A) 'hello "World"'. B) 'hello("World")'. C) 'hello.World()'. D) 'call hello("World")'. Show Answer Correct Answer: B) 'hello("World")'. 52. Def fun():print('Hello User')is an example of A) Function having no parameter and no return value. B) Function having no parameter and but return value. C) Function having parameter and result. D) Function having parameter and return value. Show Answer Correct Answer: A) Function having no parameter and no return value. 53. Which type of data type requires the 'global' keyword to modify a global variable inside a function? A) String type. B) Immutable type. C) Mutable type. D) Integer type. Show Answer Correct Answer: B) Immutable type. 54. What Is The Output Of The Following Code Snippet? def func(message, num = 1):print(message * num) func('Welcome')func('Viewers', 3) A) Welcome Viewers. B) WelcomeViewers, Viewers, Viewers. C) Welcome. D) WelcomeViewersViewersViewers. Show Answer Correct Answer: D) WelcomeViewersViewersViewers. 55. What is a situation where you would want to use a function to simplify(make easier to read) your code? A) Simple arithmetic calculation. B) Calculating the average of a list of numbers. C) Sequential operations. Example:Add one to a number. D) Insert a variable inside a string. Show Answer Correct Answer: B) Calculating the average of a list of numbers. 56. Which statement about local variables is TRUE? A) Local variables can be accessed from anywhere in the programme. B) Local variables must be integers. C) Local variables are accessible only within the function where they are defined. D) Local variables are always global. Show Answer Correct Answer: C) Local variables are accessible only within the function where they are defined. 57. Which of the following statements is true about lambda functions? A) They are useful for short, simple functions. B) They can contain multiple expressions. C) They can have a name. D) They are defined using the 'def' keyword. Show Answer Correct Answer: A) They are useful for short, simple functions. 58. Functions help us to break the program into smaller chunks A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 59. What is the purpose of the pass keyword? A) To create empty functions. B) To terminate a function. C) To define a function. D) To call a function. Show Answer Correct Answer: A) To create empty functions. 60. Can a function in Python return multiple values? A) Maybe. B) Yes. C) Only if using a specific library. D) No. Show Answer Correct Answer: B) Yes. ← PreviousNext →Related QuizzesScience QuizzesClass 11 QuizzesClass 11 Computer Science Chapter 5 Functions In Python Quiz 1Class 11 Computer Science Chapter 5 Functions In Python Quiz 2Class 11 Computer Science Chapter 5 Functions In Python Quiz 3Class 11 Computer Science Chapter 5 Functions In Python Quiz 4Class 11 Computer Science Chapter 5 Functions In Python Quiz 5Class 11 Computer Science Chapter 5 Functions In Python Quiz 7Class 11 Computer Science Chapter 1 Computer Fundamentals QuizClass 11 Computer Science Chapter 2 Introduction To Python Quiz 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books