
Python-Functions
Quiz
•
Computers
•
9th Grade
•
Practice Problem
•
Medium
Zubaidah Shaheen
Used 1+ times
FREE Resource
Enhance your content in a minute
17 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the correct way to call a function named print_sum?
def print_sum():
print_sum
print_sum():
print_sum()
Answered
Answer explanation
The correct way to call a function in Python is by using its name followed by parentheses. Therefore, 'print_sum()' is the correct choice, as it indicates a function call. The other options are either definitions or incomplete.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is the correct way to declare a function in Python?
print_hello:
print("hello")
function print_hello():
print("hello")
print_hello():
print("hello")
def print_hello():
print("hello")
Answer explanation
The correct way to declare a function in Python is using the 'def' keyword. Thus, 'def print_hello(): print("hello")' is the right choice, as it properly defines a function named 'print_hello' that prints 'hello'.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following code samples correctly passes the number 10 as an argument to the function print_number?
print_number(10)
print_number()
print 10
10(print_number)
print print_number
print 10
Answer explanation
The correct choice is print_number(10) because it directly calls the function print_number with 10 as an argument. The other options do not correctly pass 10 to the function.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following code samples correctly creates a function that takes a single parameter and prints it?
def print_number(x):
print(x)
def print_number():
print(parameter)
def print_number():
print(x)
def print(x)
Answer explanation
The correct choice is 'def print_number(x): print(x)'. It defines a function that takes a parameter 'x' and prints it. The other options either lack parameters or reference undefined variables.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In which namespace is the variable ‘x’ defined in the following program?
Function namespace
Global namespace
Object namespace
Class namespace
Answer explanation
The variable 'x' is defined in the global namespace because it is accessible throughout the program, not limited to a specific function, class, or object. Thus, the correct answer is the Global namespace.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider this code snippet.
Which of the following additional functions could be safely added to this code, without causing an error?
def subtract_nums():
z = x - y
print(z)
def subtract_nums():
z = z - x
print(z)
def subtract_nums():
y = 5
z = x - y
print(z)
def subtract_nums():
z = y
z = x - y
print(z)
Answer explanation
The correct choice defines 'y' locally, ensuring 'x' is used without errors. The other options either reference undefined variables or modify 'z' incorrectly, leading to potential errors.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following functions successfully returns the number 10?
def my_function():
10
def my_function(10):
return
def my_function():
return 10
def my_function():
print(10)
Answer explanation
The function 'def my_function(): return 10' correctly returns the number 10. The other options either do not return a value or do not use the return statement properly.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
12 questions
PowerPoint Quiz
Quiz
•
7th Grade - University
19 questions
GCSE 3.4 Computer systems - Hardware & Software
Quiz
•
9th - 11th Grade
15 questions
Cyber Security Homework 1
Quiz
•
7th - 9th Grade
16 questions
DATA SCIENCE Assessment (April)
Quiz
•
8th - 12th Grade
20 questions
End of year quiz: Python
Quiz
•
9th Grade
16 questions
Loops Quiz
Quiz
•
9th - 12th Grade
13 questions
Word Session Quiz
Quiz
•
7th Grade - University
20 questions
Microsoft Excel Units 1-3 Test
Quiz
•
9th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
