wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Method Python

Total questions: 28

Worksheet time: 24mins

Name
Class
Date
1.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
2.
What will print?
a)
nothing
b)
sayHi()
c)
an error message
d)
hi there
3.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
4.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
5.
Which of the following best describes the order in which these lines are processed in Python?
a)
4, 1, 2
b)
4, 2, 1
c)
1, 2, 3, 4
d)
3, 1, 2
6.

Which statement is the function definition?

a)

def square(x):

b)

return a

c)

a = pow(x,2)

7.
Tells the interpreter that the code which follows is a function
a)
const
b)
int
c)
def
d)
while
8.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)
It displays something like a string or integer
d)
It loops the code.
9.
A location in memory used to store data that can be changed.
a)
Constant
b)
Value
c)
Variable
d)
Iteration
10.

The function definition line must end with a

a)

semi-colon

b)

colon

c)

parenthesis

11.

Give your function a name that

a)

describes what it does

b)

is easily remembered

c)

is the title of a nursery rhyme

12.

When you use your function in your program, that is called the function

a)

definition

b)

call

c)

return

13.

When you call your function in your program, you say its name followed by

a)

parenthesis

b)

colon

c)

semi-colon

14.

Inside the parenthesis of the function call you can send the ____________ your function will use.

a)

arguments

b)

answers

c)

methods

15.

You may call a function inside another function.

a)

True

b)

False

16.

You must put your function definition

a)

at the end of your program

b)

in a separate file

c)

at the beginning of your program

17.

What word causes a function to stop?

a)

return

b)

end

c)

stop

18.

The DRY principle means

a)

don't repeat yourself

b)

use functions so that you don't write the same code over and over

c)

both answers are correct

19.

Bad, repetitive code is said to abide by the WET principle, which stands for

a)

Write Everything Twice

b)

We Enjoy Typing

c)

Both answers are correct

20.

The words in front of the parentheses are function names, and the comma-separated values inside the parentheses are function

a)

definitions

b)

arguments

c)

calls

21.

The code block that defines a function is indented

a)

true

b)

false

22.

Variables created inside a function definition can be used in other parts of the program.

a)

true

b)

false

23.

It is common practice to put a comment containing an explanation of the function below the function's first line.

a)

true

b)

false

24.

Modules are pieces of code that other people have written to fulfill common tasks, such as generating random numbers, performing mathematical operations, sorting lists, appending to lists, etc

a)

true

b)

false

25.

We use modules by using the ________ command at the top of our program

a)

import

b)

export

c)

def

26.

To import only the pi constant from the math module use the following code:

a)

from math import pi

b)

import math.pi

c)

import pi_math

27.

When using a module like sort or append, the format is

a)

list.sort

b)

list(sort):

28.

What will print?

a)

nothing

b)

5

c)

6

d)

an error message