Question

UNIT 3 Lesson 11 Functions Unit Test

Answers

GPT 3.5
1. What is a function in programming?

a) a type of variable
b) a specific sequence of code that performs a specific task
c) a loop structure
d) a conditional statement

Answer: b) a specific sequence of code that performs a specific task

2. Which of the following is a correct way to define a function in Python?

a) function add_numbers(num1, num2):
b) define add_numbers(num1, num2):
c) def add_numbers(num1, num2):
d) function add_numbers(num1, num2)

Answer: c) def add_numbers(num1, num2):

3. What does the return statement do in a function?

a) prints a message to the console
b) exits the function and returns a value
c) defines the function
d) loops through a block of code

Answer: b) exits the function and returns a value

4. Which of the following is the correct syntax to call a function in Python?

a) call add_numbers(num1, num2)
b) add_numbers(num1, num2)
c) function add_numbers(num1, num2)
d) execute add_numbers(num1, num2)

Answer: b) add_numbers(num1, num2)

5. What is the output of the following code snippet?

```python
def multiply_nums(num1, num2):
product = num1 * num2
return product

result = multiply_nums(3, 4)
print(result)
```

a) 7
b) 12
c) 10
d) 6

Answer: b) 12

6. Why are functions useful in programming?

a) They allow us to reuse code and avoid repetition.
b) They help organize code into smaller, more manageable pieces.
c) They make code more readable and easier to understand.
d) All of the above

Answer: d) All of the above

7. Can a function have multiple return statements?

a) Yes
b) No

Answer: a) Yes

8. What is the output of the following code snippet?

```python
def check_odd(num):
if num % 2 == 0:
return False
else:
return True

is_odd = check_odd(5)
print(is_odd)
```

a) True
b) False
c) None
d) 5

Answer: a) True