SWAYAM
Programming in Python
Assignment 9 due: 20.04.24
1. Which of the following is a built-in function in Python?
• a. def
• b. lambda
• c. return
• d. yield
• Answer: def
2. Which of the following statements is true about functions in Python?
• a. Functions cannot return any value.
• b. Functions in Python must be defined using the function keyword.
• c. Functions in Python can take arguments and return values.
• d. Functions in Python cannot call other functions.
• Answer: c. Functions in Python can take arguments and return values.
3. What is the purpose of the return statement in a Python function?
• a. To terminate the function execution.
• b. To print a value to the console.
• c. To define a new variable.
• d. To return a value from the function.
• Answer: d. To return a value from the function.
4. In Python, what is a parameter in a function?
• a. A variable that holds the return value of the function.
• b. A variable that holds a value passed to the function.
• c. A variable that is defined inside the function.
• d. A variable that is declared globally.
• Answer: b. A variable that holds a value passed to the function.
5. What is the output of the following code?
pythonCopy code
def add(x, y): return x+10, y+10 result = add(14, 15) print(result)
• a. (24, 25)
• b. (14, 15)
• c. 49
• d. Error
• Answer: a. (24, 25)
6. Which of the following is the correct way to call a function named my_function with two
arguments a and b?
• a. my_function a, b
• b. my_function(a, b)
• c. my_function(a b)
• d. my_function(a b)
• Answer: b. my_function(a, b)
7. What is the output of the following code?
pythonCopy code
def outer_func(x, y): def inner_func(m, n): return m + n return inner_func(x, y) return x result =
outer_func(5, 10) print(result)
• a. 15
• b. 5
• c. 10
• d. 50
• Answer: a. 15
8. What is the purpose of the *args parameter in a function definition?
• a. To allow the function to accept a variable number of arguments.
• b. To define a default value for an argument.
• c. To allow the function to accept a keyword argument.
• d. To define a required argument.
• Answer: a. To allow the function to accept a variable number of arguments.
9. Which of the following is the correct syntax to define a lambda function in Python?
• a. def my_lambda(): x + 1
• b. lambda x: x + 1
• c. lambda(x): return x + 1
• d. function lambda(x): return x + 1
• Answer: b. lambda x: x + 1
10. What will be the output of the following code?
pythonCopy code
def my_function(*fruits): print(fruits[0]) my_function("Apple", "Mango", "Banana","Kiwi")
• a. Apple
• b. Mango
• c. Banana
• d. Kiwi
• Answer: a. Apple