Python-Functions

Python-Functions

9th Grade

17 Qs

quiz-placeholder

Similar activities

Bermain Gambar

Bermain Gambar

1st Grade - Professional Development

15 Qs

Grade 9 Quiz # 1 Q2

Grade 9 Quiz # 1 Q2

9th Grade

20 Qs

AI-1

AI-1

KG - University

13 Qs

End of term assessment

End of term assessment

9th Grade

15 Qs

Grade 9 Checkpoint 1 Revision

Grade 9 Checkpoint 1 Revision

9th Grade

15 Qs

Spreadsheet

Spreadsheet

8th Grade - University

20 Qs

LATIHAN SIMDIG

LATIHAN SIMDIG

9th - 12th Grade

20 Qs

Python-Functions

Python-Functions

Assessment

Quiz

Computers

9th Grade

Practice Problem

Medium

Created by

Zubaidah Shaheen

Used 1+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

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?

  1. def print_sum():


  1. print_sum


  1. print_sum():


  1. 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

Media Image

In which namespace is the variable ‘x’ defined in the following program?

  1. 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

Media Image

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

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?