wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Test

Total questions: 100

Worksheet time: 1hrs 8mins

Name
Class
Date
1.

Which two (2) lines of code will print when this function is called?

4 lines
2.

What is the name of the function?

4 lines
3.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

4.

Which two (2) lines of code will print when this function is called?

4 lines
5.

What is the name of the function?

4 lines
6.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

7.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
8.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

9.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

10.

Which of the following is the correct code to define a function?

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

11.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
12.

How do you identify the statements that belong to the body of a function?

a)

Indent those statement the same amount underneath the function "def" statement

b)

Add opening and closing curly braces { and } to mark the start and stop of the function body

c)

Add the "def" keyword to the beginning of each statement

d)

Add the same comment (#) to the right of each statement within the body

13.

What character should be placed at the end of the function "def" line, after the parentheses?

a)

Hashtag (#)

b)

Colon(:)

c)

Exclamation (!)

d)

Dash (-)

14.

Which keyword marks a spot in a function where the program flow will go back to the calling code?

a)

break

b)

return

c)

continue

d)

jump

15.

If a function named "mystery" is defined as taking no parameters, how would you call that function from your code?

a)

#mystery

b)

mystery[]

c)

mystery()

d)

mystery

16.

Which of the following best describes where you should define your function in your code?

a)

Near the bottom of the source file, after that function is called by any main program code

b)

Always place functions in a separate source file

c)

Near the top of the source file, before that function is called by any main program code

d)

The location is not important, so place the function wherever you like

17.

Which of the following is NOT a Python rule for naming functions?

a)

Functions names can contain letters, numbers and underscores

b)

Function names must be less than 32 characters

c)

The first character in a function name cannot be a number

d)

Function names are case-sensitive

18.

Which of the following statements correctly defines a function named "haunted" that takes a parameter named "apple"?

a)

haunted(apple)

b)

haunted

c)

def haunted(apple):

d)

apple

19.

. Which of the following definitions for the "haunted" function will correctly set the default value for the "surprise" parameter equal to the number 1?

a)

haunted(fear, surprise) = 1

b)

def haunted(fear, surprise=1):

c)

def haunted(fear, surprise "1")

d)

def haunted[fear, surprise=1]

20.

Which of the following statements will successfully send the value "EEK" back from a function to the calling code?

a)

EEK

b)

return EEK

c)

back EEK

d)

#print(EEK)

21.

How many return statements can you place inside one function body?

a)

As many as needed; each marks a spot where program flow returns to the calling code

b)

You can have one return statement per parameter that is defined by the function "def"

c)

You are limited by the number of body statements, divided by 2

d)

Exactly one

22.

What controls a variable's scope?

a)

The location where it is first initialized within your code

b)

The comment you place to the right of the variable name

c)

The capitalization you select for the letters in your function name

d)

The length of your variable name

23.

Which of the following rules is true about locally scoped variables?

a)

Local variables can hold less data than global variables

b)

Local variables can be seen and accessed from any part of the program code

c)

Local variables will keep their same value over repeated calls to the function

d)

Local variables can only be seen and used from inside a function

24.

Print statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

A loop controlled by a decision

25.

Input statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

A loop controlled by a decision

26.

If else statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

A loop controlled by a decision

27.

While statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

A loop controlled by a decision

28.

For statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

A loop controlled by a counter

29.

Def statement

a)

Outputs a message on the screen

b)

Gets data from the user

c)

A decision

d)

Create a procedure or function

30.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble
31.
What is python?
a)
a programming language 
b)
DTP software 
c)
Spreadsheet software
d)
Computer 
32.

How is Python similar to Scratch?

a)

They are both text-based languages.

b)

They are not similar.

c)

They are both number based languages.

33.
What will the output be from the following code?
print("Hello world!")
a)
SyntaxError
b)
Hello world!
c)
"Hello world!"
d)
print(Hello world!)
34.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

35.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

36.

What will this output?

a)

Mine is too!

b)

An error

c)

MINE IS TOO!

d)

Nothing

37.

What will be the output of this code?
x = 13

y = 14

if x==y:

print("Hello")

else:

print("Hi")

a)

Hello

b)

Hi

c)

13

d)

14

38.

What will be the output of this code?
x = 13

y = 14

if x!=y:

print("Hello")

else:

print("Hi")

a)

Hello

b)

Hi

c)

14

d)

13

39.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
40.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

Sorry! Not tall enough!

d)

There will be an error.

41.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

You cannot ride the carousel!

d)

There will be an error.

42.

How do you define(assign) variables?

a)

var="String"

b)

func==Hello

c)

var : 123

d)

word= Hello

43.

What is the end after if statements?

a)

if

b)

Elif

c)

Else

d)

While

44.

Which of the following is a correctly-formatted comment?

a)

*Comment

b)

"Comment"

c)

#comment

d)

(comment)

45.

A line of text that Python won't try to run as code

a)

Integer

b)

Comment

c)

Strings

d)

Input

46.

What will be the value of last_jedi after the following code is run?

a)

["kylo", "rey", "finn", "luke"]

b)

["kylo", "rey", "finn"]

c)

3

d)

4

47.

What will this code print?

a)

6

b)

1

c)

pants

d)

"pants": 6

48.

What is the correct syntax to write a for loop to iterate through the list grades?

a)

for variable:

b)

for variable in grades

c)

variable in grades:

d)

for variable in grades:

49.

What will be the value of colors after the following code is run?

a)

["light blue", "pink"]

b)

["light blue", "yellow", "pink"]

c)

["pink", "yellow"]

d)

["light blue", "yellow"]

50.

What will be the value of n after the following code is run?

a)

[6]

b)

[1, 8, 6, 4, 2]

c)

[8, 6, 4, 2, 1]

d)

[8, 4, 2]

51.

What will be the value of n after the following code is run?

a)

[2, 2, 3, 5]

b)

[1, 2, 4, 5]

c)

[1, 3, 3, 5]

d)

[2, 3, 4, 6]

52.

What will be the value of n after the following code is run?

a)

[1, 3, 5]

b)

[3]

c)

[1, 5, 7]

d)

[1, 3, 7]

53.

How many lines will the code below print to the console?

a)

4

b)

5

c)

2

d)

3

54.

Which of the following is the correct way to create an empty list?

a)

empty_list = []

b)

empty_list = {}

c)

empty_list = [0]

d)

empty_list = None

55.

What is the output of the following code?

a)

"Moonlight"

"Casey Affleck"

"Emma Stone"

"Zootopia"

b)

("Best Picture", "Moonlight")

("Best Actor", "Casey Affleck")

("Best Actress", "Emma Stone")

("Animated Feature", "Zootopia")

c)

"Best Picture"

"Best Actor"

"Best Actress"

"Animated Feature"

d)

"Best Picture" : "Moonlight"

"Best Actor": "Casey Affleck"

"Best Actress": "Emma Stone"

"Animated Feature": "Zootopia"

56.

What will the following code output?

a)

"soda"

b)

KeyError

c)

["veggie burger", "salad", "soda"]

d)

["hamburger", "fries", "soda"]

57.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

58.

Which of the following are true of Python dictionaries:

a)

Dictionaries can be nested to any depth.

b)

Dictionaries are accessed by key.

c)

All the keys in a dictionary must be of the same type.

d)

Dictionaries are mutable.

e)

A dictionary can contain any object type except another dictionary.

59.

A Python dictionary stores ...

a)

value - key pairs

b)

key - value pairs

60.
What data type is this?
quiz = {"Do you help out at home? ":"yes",        
"Do you beleive in Santa? ":"yes"
}
a)
list
b)
string
c)
dictionart
d)
dictionary
61.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

62.
A data type consisting of numbers, letters and symbols.
a)
String
b)
Integer
c)
Float
d)
Boolean
63.

What is the output from this code?

a)

ell

b)

llo

c)

ello,

d)

Hello

64.

str1="101"

x=int(str1)

z=x+400

print(z)

a)

101400

b)

x400

c)

501

d)

none of above

65.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

66.
What is printed?
cheer = "Go Eagles!"
print cheer[1:4]
a)
Go E
b)
o E
c)
"o E"
d)
nothing - there is an error
67.

What will the output be from the following code?

print("Hello world!" * 2)

a)

TypeError

b)

Hello world world!

c)

Hello world!Hello world!

d)

Hello world! * 2

68.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

69.
What does the len() function do?
a)
Gets the length of a string or list
b)
Gets the character code for a character
c)
Converts a character into a character code
d)
Would you like a muffin?
70.

Which of these is a list?

a)

fruit = ["apples", "oranges", "bananas"]

b)

fruit = "apples", "oranges", "bananas"

c)

fruit = {"apples", "oranges", "bananas"}

d)

fruit = ("apples", "oranges", "bananas")

71.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

72.

a)

["a", "b", "c"]

b)

["a"]

c)

["a", "b"]

d)

[]

73.

a)

a

b)

b

c)

c

d)

Error

74.

a)

1

b)

2

c)

3

d)

4

75.

a)

["o"]

b)

["a", "b", "c", "o"]

c)

o

d)

["c", "o"]

76.

a)

["a", "c"]

b)

["b"]

c)

["a", "b", "c"]

d)

["a", "b", "c", "b"]

77.

A (a)   is a data structure that can hold more than 1 value at a time. It is a collection or ordered series of elements of the same type.

78.

We can create an array that is able to store any data type.

a)

True

b)

False

79.

Arrays are ...................data types?

a)

built-in

b)

user defined

c)

computer

d)

analysis

80.

The total number of elements in the array is called...............

a)

Length

b)

memory

c)

index

d)

subscript

81.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
82.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
83.

What is a Boolean?

a)

True or False statement

b)

Numerical Operator

c)

A cube that is used for a soup base.

d)

A Ghost on a tree

84.

What does the following comparison operator “!=” represent in Python programming?

a)

Equal to

b)

Assignment

c)

Allocation

d)

Not equal to.

85.

What is the result of the following code?

print(10 == 9)

a)

True

b)

False

86.

What is the result of the following code?

print(10 != 9)

a)

True

b)

False

87.

In Python the multiplication sign is...

a)

*

b)

%

c)

.

d)

'

88.

What is an expression in Python

a)

something i feel strongly about

b)

a math problem

c)

a saying with a meaning behind it

d)

syntax

89.

in Pyton the exponent or power sign is

a)

^

b)

**

c)

>

d)

"

90.

Syntax is...

a)

an error

b)

a coding language that explains Python what to do

c)

rules we follow in building sentences

d)

ways to express yourself

91.

What is the truth value for the compound Boolean statement?

5 == 2 + 3 or 7 > 8

a)

True

b)

False

c)

No Value

92.

In the provided code, what is the final output?

a)

"Fred"

b)

15

c)

25

d)

35

93.

In the provided code, which lines of code will be skipped by the computer when the program is run?

a)

7

b)

7, 10, 11

c)

10, 11

d)

7, 10

94.

Which code means not equal to?

a)

==

b)

<=

c)

>

d)

!=

95.

What is the name of the function?

4 lines
96.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

97.

What can be used to store information and values so that it can be used later?

a)

Graphic

b)

Variable

c)

Print

d)

Output

98.

What is the word (command) used to display numbers and text on the screen?

a)

print

b)

show

c)

output

d)

command

99.

What will be the output?

name = 'Dave'

print (name)

a)

name

b)

print

c)

Dave

d)

error

100.

What is a input?

a)

To plug in something.

b)

A function that allows us to ask the user to enter some data.

c)

Data displayed on a screen.

d)

A function