wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Mixed Concepts

Total questions: 78

Worksheet time: 41mins

Name
Class
Date
1.

What value is printed to the console?

a)

13

b)

4

c)

22

d)

17

e)

-2

2.

What is printed to the console?

a)

13

b)

4

c)

17

d)

22

3.

What value is printed to console?

a)

22

b)

17

c)

-2

d)

4

4.

thisList = ["square", "circle", "triangle", "octagon"]

print(thisList[3])

a)

octagon

b)

triangle

c)

circle

d)

square

5.

num = [1, 2, 3, 4]

num.append(0)

print(num)

What is the output?

a)

[0,1,2,3,4]

b)

[1,2,3,4,5]

c)

[0,1,2,3]

d)

[1,2,3,4,0]

6.

What is the result of the expression [x*2 for x in range(5)]?

a)

[0, 1, 2, 3, 4]

b)

[2, 4, 6, 8, 10]

c)

[1, 4, 9, 16, 25]

d)

[0, 2, 4, 6, 8]

7.

What is the difference between append() and extend() methods in Python lists?

a)

The append() method adds multiple elements to the end of the list, while the extend() method adds a single element to the end of the list.

b)

The append() method removes elements from the list, while the extend() method adds elements to the list.

c)

The append() method adds a single element to the end of the list, while the extend() method adds multiple elements to the end of the list.

d)

The append() method adds elements to the beginning of the list, while the extend() method adds elements to the middle of the list.

8.

How do you access the second element of the first list in a nested list named 'my_nested_list'?

a)

my_nested_list[0,1]

b)

my_nested_list[0][1]

c)

my_nested_list[2][1]

d)

my_nested_list[1][0]

9.

Lists are used to store single item in a single variable.

a)

True

b)

False

10.

List items are ordered, changeable, and allow duplicate values.

a)

True

b)

False

11.

List items are indexed, the first item has index [1], the second item has index [2] etc.

a)

True

b)

False

12.

When we say that lists are ordered, it means that the items have a defined order, and that order will not change.

a)

True

b)

False

13.

List items can be of any data type:

a)

True

b)

False

14.

If you add new items to a list, the new items will be placed at the end of the list.

a)

True

b)

False

15.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

16.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

17.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

18.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

19.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
20.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

21.

The count() method returns the number of times the specified element appears in the list.

What is the output of this code?

a)

3

b)

2

c)

1

d)

0

22.

Output of this code?

a)

[2,4,6,8,10]

b)

['2','4','6','8','10']

c)

[0,2,4,6,8]

d)

[10,8,6,4,2]

23.

What is the index of “grape” in the list

[“apple”, “grape”, “orange”, “watermelon”]?

a)

0

b)

1

c)

2

d)

3

24.

The program snippet above is syntactically correct

a)

False

b)

True

25.

You should be at least 18 years to vote. What should be the expression in the if statement that will print


can vote.

a)

age >= 18

b)

age = 18

c)

age == 18

26.

What is the output of the program above.

a)

can vote

b)

can drink

c)

can vote can drink

27.

What is the output of the above program

a)

can vote

can drink

b)

can vote

c)

can drink

d)

none of the above

28.

What is the output of the code above

a)

go watch cartoons

b)

can vote

c)

go get a girlfriend/boyfriend

29.

For which value of age, will the output "go drink" get printed

a)

It will never print

b)

17

c)

22

30.

The program above will print

a)

Nothing

b)

tends to drink

c)

tends to chitchat

31.

The code above will print

a)

python

b)

java

c)

None

32.

Consider the Python code snippet shown.

What is the value of the 'total' variable after this code is executed?

a)

0

b)

3

c)

6

d)

10

33.

In Python, what is the purpose of the "break" statement in a loop?

a)

It skips the current iteration and continues to the next one

b)

It exits the loop prematurely

c)

It prints a message to the console

d)

It restarts the loop from the beginning

34.

Consider the code snippet shown.

What will be the output of this code?

a)

5, 4, 3

b)

5, 4, 3, 2

c)

5, 4, 3, 2, 1

d)

2, 1

35.

Which of the following is not a comparison operator in Python?

a)

==

b)

<=

c)

&&

d)

>

36.

Consider the code snippet shown.

What will be the output of this code?

a)

1,2,3

b)

1,2,3,4

c)

1,2,3,4,5,6

d)

1,2,3,2,4,3

37.

What does the "continue" statement do in a loop in Python?

a)

Exits the loop

b)

Skips the remining code in current iteration and starts the next one

c)

Starts a new iteration

d)

Raises an error

38.

Consider the following code snippet.

What will be the output of the code?

a)

1,3,5

b)

2,4

c)

1,2,3,4,5

d)

1,3

39.

In Python, what is the purpose of an "elif" statement?

a)

It represents the end of a loop

b)

It is used to define functions

c)

It is short for "else if" and adds additional conditions

d)

Exits the current loop prematurely

40.

Consider the code snippet shown.

What will be the output of the code?

a)

1,4,9

b)

1,2,3,4,5,6,7,8,9

c)

2,4,6

d)

3,6,9

41.

What is the purpose of conditional statements in Python?

a)

To repeat a block of code

b)

To perform different actions based on conditions

c)

To define functions

d)

To print output to the console

42.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
43.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
44.
What will the following lines of code print?
a)
A
b)
B C
c)
A C
d)
Nothing, it will return an error.
45.
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:
46.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

47.

What is syntax?

a)

a catch-all for every other situation besides true.

b)

pieces of code that direct the program to run in different ways depending on what else is happening.

c)

a set of rules for how a language is written.

d)

English, Chinese, or Spanish.

48.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

49.

This is a catch-all for every other situation besides the one where the condition is true.

a)

then

b)

do

c)

else

d)

if

50.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

51.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

52.

Data type that can only be true or false

a)

int

b)

string

c)

boolean

d)

float

53.

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

a)

:

b)

;

c)

.

d)

{

54.
What symbol do you use to make a comment in Python?
a)
@
b)
¬
c)
;
d)
#
55.

1. Which of the functions is called when z = 12?

a)

sayHi()

b)

sayHello()

c)

sayGoodbye()

56.

Which of the following is true about if-elif-else statements?

a)

After using if, an elif can be added as an additional test

b)

The bodies of multiple elif’s can run

c)

You can use an elif without an if

d)

Code in an else body runs if all the tests before it were True

57.

What shape will be in front if x = 5?

a)

r

b)

c

c)

s

58.

What shape will be in front if x = 6?

a)

r

b)

c

c)

s

59.

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

4 lines
60.

What is the name of the function?

4 lines
61.

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

a)

true

b)

false

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

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

64.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

65.

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

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

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

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

68.

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

a)

Hashtag (#)

b)

Colon(:)

c)

Exclamation (!)

d)

Dash (-)

69.

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

70.

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

71.

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

72.

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

73.

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

74.

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

75.

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)

76.

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

77.

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

78.

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