Question
Lesson 11 unit 8 functions unit test
Answers
GPT 3.5
1. What is a function?
a) A variable that stores a value
b) A set of instructions that perform a specific task
c) A data structure that organizes information
d) A loop that repeats a certain action
2. What is the purpose of a function in programming?
a) To store multiple values
b) To make the code more organized and easier to read
c) To create complex data structures
d) To create infinite loops
3. Which keyword is used to define a function in most programming languages?
a) loop
b) def
c) var
d) return
4. What is a parameter in a function?
a) A variable that stores a value
b) A keyword that defines the function
c) A value that is passed into the function when it is called
d) An if statement that checks a condition
5. What is the return statement used for in a function?
a) To print a value to the console
b) To define a variable
c) To stop the function from running
d) To return a value from the function to where it was called
6. How do you call a function in your code?
a) By using the def keyword
b) By defining a new parameter
c) By typing the function name followed by parentheses
d) By using the return statement
7. What is the difference between a function declaration and a function call?
a) There is no difference, they are the same thing
b) A function declaration defines the function, while a function call executes the function
c) A function call defines the function, while a function declaration executes the function
d) A function declaration is used for loops, while a function call is used for variables
8. What is the output of the following code?
```python
def add_two_numbers(num1, num2):
return num1 + num2
result = add_two_numbers(3, 5)
print(result)
```
a) None
b) 3
c) 5
d) 8
9. Which of the following is NOT a built-in function in Python?
a) print()
b) input()
c) add()
d) range()
10. What is the purpose of using functions in programming?
a) To make the code more complex
b) To make the code less readable
c) To improve code reusability and organization
d) To slow down the execution of the code
Answers:
1. b) A set of instructions that perform a specific task
2. b) To make the code more organized and easier to read
3. b) def
4. c) A value that is passed into the function when it is called
5. d) To return a value from the function to where it was called
6. c) By typing the function name followed by parentheses
7. b) A function declaration defines the function, while a function call executes the function
8. d) 8
9. c) add()
10. c) To improve code reusability and organization
a) A variable that stores a value
b) A set of instructions that perform a specific task
c) A data structure that organizes information
d) A loop that repeats a certain action
2. What is the purpose of a function in programming?
a) To store multiple values
b) To make the code more organized and easier to read
c) To create complex data structures
d) To create infinite loops
3. Which keyword is used to define a function in most programming languages?
a) loop
b) def
c) var
d) return
4. What is a parameter in a function?
a) A variable that stores a value
b) A keyword that defines the function
c) A value that is passed into the function when it is called
d) An if statement that checks a condition
5. What is the return statement used for in a function?
a) To print a value to the console
b) To define a variable
c) To stop the function from running
d) To return a value from the function to where it was called
6. How do you call a function in your code?
a) By using the def keyword
b) By defining a new parameter
c) By typing the function name followed by parentheses
d) By using the return statement
7. What is the difference between a function declaration and a function call?
a) There is no difference, they are the same thing
b) A function declaration defines the function, while a function call executes the function
c) A function call defines the function, while a function declaration executes the function
d) A function declaration is used for loops, while a function call is used for variables
8. What is the output of the following code?
```python
def add_two_numbers(num1, num2):
return num1 + num2
result = add_two_numbers(3, 5)
print(result)
```
a) None
b) 3
c) 5
d) 8
9. Which of the following is NOT a built-in function in Python?
a) print()
b) input()
c) add()
d) range()
10. What is the purpose of using functions in programming?
a) To make the code more complex
b) To make the code less readable
c) To improve code reusability and organization
d) To slow down the execution of the code
Answers:
1. b) A set of instructions that perform a specific task
2. b) To make the code more organized and easier to read
3. b) def
4. c) A value that is passed into the function when it is called
5. d) To return a value from the function to where it was called
6. c) By typing the function name followed by parentheses
7. b) A function declaration defines the function, while a function call executes the function
8. d) 8
9. c) add()
10. c) To improve code reusability and organization