wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CodeHS Python Cert Rev 1

Total questions: 65

Worksheet time: 2hrs 31mins

Name
Class
Date
1.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

2.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

3.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

4.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

5.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

6.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

7.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

8.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

9.

Please answer the question in the image:

a)

A

b)

B

c)

C

d)

D

10.

In python, what is output?

a)

Built-in tools, such as print

b)

Text in parentheses

c)

The name of a variable

d)

The result of the code, what is seen when it runs

11.

In python, what is a function?

a)

Built-in tools, such as print

b)

Text in parentheses

c)

The name of a variable

d)

The result of the code, what is seen when it runs

12.

In python, what is a parameter value?

a)

Built-in tools, such as print

b)

Text in parentheses

c)

The name of a variable

d)

The result of the code, what is seen when it runs

13.

Which of these is NOT a type of data that can be a variable?

a)

Comments

b)

Integers

c)

Strings

d)

Boolean values

14.

Info a program receives from a user is:

a)

Input

b)

Output

c)

String

d)

Comment

e)

Error

15.

A line of code ignored by the computer is:

a)

Input

b)

Output

c)

String

d)

Comment

e)

Error

16.

A series of letters, numbers, or symbols in quotation marks is:

a)

Input

b)

Output

c)

String

d)

Comment

e)

Error

17.

What is it called when you join two strings together with the + symbol?

a)

Assignment

b)

Concatenation

c)

Value

d)

Float

e)

Integer

18.

What is a number that has a decimal point?

a)

Assignment

b)

Concatenation

c)

Value

d)

Float

e)

Integer

19.

What is a whole number?

a)

Assignment

b)

Concatenation

c)

Value

d)

Float

e)

Integer

20.

What is the process for storing a variable? (x = y, for example?)

a)

Assignment

b)

Concatenation

c)

Value

d)

Float

e)

Integer

21.

What symbol is used at the beginning of an in-line comment?

a)

"

b)

!

c)

#

d)

/

22.

Which of the statement are NOT true about comments:

a)

Written for humans to read and understand

b)

Helps other programmers understand your code

c)

Helps keep the programmer organized

d)

Only needed when a program is over 50 lines

23.

What punctuation is needed to begin a multi-line comment?

a)

$

b)

"""

c)

*

d)

/

24.
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
25.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
26.

What syntax would you use to create a name variable?

a)

name=input()

b)

input=name

c)

name=input{}

d)

name=INPUT

27.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
28.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
29.

Which operator checks if a value is equal to another value?

a)

+

b)

=

c)

==

d)

!=

30.
a data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulo
d)
interpreter
31.

How many times will the following loop run?

a)

3 times

b)

4 times

c)

5 times

d)

The loop will run indefinitely

32.

Which of the following is true about the following code?

a)

The code contains a syntax error

b)

The code contains two comments

c)

The code will print the comments to the console

d)

The code will not run because of the comment on line 2

33.

What is the result of executing the following list operation?

a)

[1, 6, 7, 5]

b)

[1, 2, 3, 6, 7]

c)

[6, 7, 5]

d)

[1, 6, 7, 7, 5]

34.

What is the purpose of the continue statement in loops? Select ALL that are TRUE! (multiple correct answers)

a)

It passes control to the next iteration of the loop, or ends the loop if there is no next iteration.

b)

It exits the loop immediately

c)

It restarts the loop from the beginning

d)

It skips the rest of the code inside the loop for the current iteration

35.

What will be the output of the following code?

a)

['data']

b)

['data', 'data']

c)

[]

d)

An error occurs

36.

What is the output of the following code snippet? guess = '65.83' print(float(guess) + 1)

a)

66.83

b)

66

c)

65.84

d)

66.8

37.

Which operator should be used in place of "?" to make the following expression evaluate to True? (5 ? 3) and (2 < 4)

a)

>

b)

<=

c)

!=

d)

==

38.

What is the result of the following? print(17 % 3)

a)

5

b)

4

c)

3

d)

2

39.

In a number guessing game, which conditional statement would check if `guess` is equal to `15`?

a)

if guess = 15:

b)

if guess == 15:

c)

if guess: 15

d)

if guess is 15:

40.

What will the following loop print for a number guessing game where `number` is `10`? for i in range(3): if i == number: print("Correct!") break print("Incorrect!")

a)

Correct!

b)

Incorrect!

c)

Correct! Incorrect! Incorrect!

d)

Incorrect! Incorrect! Incorrect!

41.

In which case will the loop continue indefinitely? while guess != number: guess = int(input("Enter your guess: "))

a)

`guess` is initialized as a string

b)

`number` changes within the loop

c)

`guess` is initialized with the same value as `number`

d)

`input` function is not used

42.

In Python, what symbol is used to begin a comment?

a)

//

b)

/*

c)

#

43.

In Python, which of the following is an error?

a)

Starting a line with a space

b)

Having extra spaces at the end of a line

c)

Not indenting under a function definition

d)

Using tabs for indentation

44.

How can you define a function `is_correct_guess` to accept two parameters, `guess` and `number`?

a)

def is_correct_guess[guess, number]:

b)

def is_correct_guess{guess, number}:

c)

def is_correct_guess(guess number):

d)

def is_correct_guess(guess, number):

45.

In the context of a number guessing game, which error will be raised if an input is not an integer?

a)

TypeError

b)

ValueError

c)

IndexError

d)

KeyError

46.

Given the list `numbers = [1, 2, 3, 4]`, how would you add the number `5` to the end of the list?

a)

numbers.append(5)

b)

numbers.add(5)

c)

numbers += 5

d)

numbers.insert(5)

47.

For `matrix = [[1, 2], [3, 4]]`, how do you access the element `3`?

a)

matrix[1][0]

b)

matrix[1][1]

c)

matrix[2][1]

d)

matrix[0][1]

48.

In the string `'Guess: 15'`, how can you extract only the number as an integer?

a)

int('Guess: 15'[6:])

b)

int('Guess: 15'.split()[1])

c)

'Guess: 15'[7:].to_int()

d)

'Guess: 15'.split(':')[1].int()

49.

Which string method would you use to check if a string `s` starts with "Guess"?

a)

s.startswith("Guess")

b)

s.begin("Guess")

c)

s.starts("Guess")

d)

s.begin_with("Guess")

50.

If `guess = " 15 "`, which of the following would remove the leading and trailing spaces?

a)

guess.strip()

b)

guess.remove_spaces()

c)

guess.no_spaces()

d)

guess.trim()

51.

What is the benefit of using the break command as in the program below?

a)

The user can enter as many answers as they want

b)

The program will break out of the loop as soon as the user enters the magic_number

c)

The loop will prompt the user to enter a number no matter what input they give

d)

The loop will give the magic_number after a certain number of tries

52.

What will be printed to the screen when this program is run?

a)

100 0 -75 -125 -150

b)

-150

c)

-175

d)

175

53.

What does this program print?

a)

It’s still a nice day

It’s still a nice day

b)

It’s still a nice day

It’s still a nice day

It’s still a nice day

c)

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

d)

It’s still a nice day

It’s still a nice day

It’s still a nice day

It’s still a nice day

54.

What is the value of sum when this loop completes?

a)

8

b)

9

c)

20

d)

0

55.

Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?

a)

while num > 12 and num < 3:

# do something with num

b)

while num < 12 or num < 3:

# do something with num

c)

while num <= 12 and num >= 3:

# do something with num

d)

while num < 12 and num > 3:

# do something with num

56.

If the user enters ‘4’, I want the loop to exit. Where should the break command be placed in order to end the loop when the user enters this value?

a)

Line 3

b)

Line 5

c)

Line 7

d)

Line 9

57.

Which of the following for loops would print the following numbers?

3 5 7 9

a)

for i in range(3, 10, 2):

print(i)

b)

for i in range(3, 9, 2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

58.

What does this program print?

a)

0 1 2

b)

0 1 2 4 5 6 7 8 9

c)

0 1 2 3 4 5 6 7 8 9

d)

0 1 2 3

59.

When would a while loop be a better control structure to use than a for loop?

a)

When you need to repeat multiple commands

b)

When you need to repeat something 5 times

c)

When you don’t know how many times something will need to repeat

d)

When the user is inputting how many times to repeat something

60.

What is the value of num when this loop completes?

a)

2

b)

8

c)

12

d)

20

61.

Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?

a)

for i in range(0, 5):

b)

for i in range(5):

c)

for i in range(0, 5, 1):

d)

for i in range(5, 0, 1):

62.

Which of the following for loops would print the following numbers?

0 1 2 3 4 5

a)

for i in range(5):

print(i)

b)

for i in range(1, 5, 1):

print(i)

c)

for i in range(6):

print(i)

d)

for i in range(0, 5, 1):

print(i)

63.

Which of the following while loops will cause an infinite loop?

a)

b)

c)

d)

64.

What will be printed to the screen when this program is run?

a)

0 1 0 1

b)

0 2

c)

0 1 0 1 0 1

d)

1 2 1 2 1 2

65.

Which of the following for loops will give the same values for i as the loop below?

for i in range(10):

a)

for i in range(11, 0):

b)

for i in range(10, 0, -1):

c)

for i in range(0, 10):

d)

for i in range(0, 11, 1):