wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSE Final Exam Review CodeHS

Total questions: 130

Worksheet time: 33hrs 30mins

Name
Class
Date
1.

When the following for loop is complete, how many spaces will Tracy have moved?

a)

50 spaces

b)

60 spaces

c)

10 spaces

d)

5 spaces

2.

Suppose you write a function. How many times can you call the function in your code?

a)

Once

b)

Not more than the number of commands the function holds

c)

It depends on the function

d)

As many times as you want

3.

In which of the following situations would it be best to make a function?

a)

You want Tracy to draw a blue line, and your program requires lots of blue lines.

b)

You need Tracy to move forward by 100.

c)

You need Tracy to turn right and then turn left.

d)

You need to change Tracy’s color.

4.

Which of the following pieces of code will make Tracy do the following actions three times: go forward, change colors, and then turn around.

a)
b)
c)
d)
5.

Suppose you want to make Tracy draw a mountain range, like the one shown above, starting from the left side.


Which of the following functions would be the most useful function to write in order to solve this problem?

a)
b)
c)
d)
6.

Which of the following is NOT a command you can give to Tracy?

a)

color

b)

turn

c)

backward

d)

left

7.

Which of the statements below is true about indentation in Python?

a)

Indentation only matters in for loops. Then, everything must be indented one level.

b)

Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.

c)

Indentation always matters in Python. Every statement must be aligned correctly.

d)

Indentation only matters in functions. Then, everything must be indented one level.

8.

Which of the following statements are true about for loops?

a)

A, C, and F

b)

A, B, C, and F

c)

A, B, C, E, and F

d)

A and C

9.

Which of the following functions is defined correctly?

a)
b)
c)
d)
10.

Which of the following is NOT a purpose of using functions?

a)

Functions let Tracy do new things.

b)

Functions help group statements together to make your code more readable.

c)

Functions let you execute code a fixed number of times.

d)

Functions allow the programmer to reuse code.

11.

What is the difference between defining and calling a function?

a)

Defining a function means you are teaching the computer a new word. Calling a function means you are commanding the computer to complete defined actions.

b)

There is no difference.

c)

Calling a function means you are teaching the computer a new word. Defining a function means you are commanding the computer to complete defined actions.

d)

Defining a function must be done each time you want to use the function. Calling a function can only happen once in your code.

12.

What does the number in the parentheses in a forward() or backward() command represent?

a)

How many degrees Tracy is supposed to turn.

b)

How fast Tracy is supposed to move.

c)

How many times Tracy should repeat the command.

d)

How far Tracy is supposed to move

13.

What control structure would be best to use in the following code?

a)

A function

b)

A while loop

c)

A for loop

d)

An if/else statement

14.

Which of the following commands can be used to turn Tracy to face North if she is initially facing South?

a)

left(90)

right(90)

b)

right(180)

c)

right(90)

left(180)

d)

left(360)

15.

Which program below includes no errors?

a)
b)
c)
d)
16.

Which of the following commands can NOT be used to draw one square?

a)
b)
c)
d)
17.

What shape will be drawn with the following command?

circle(50, 360, 3)

a)

A circle

b)

A hexagon

c)

A triangle

d)

A diamond

18.

How can we use variable to control the size of a circle?

a)

radius = 50

circle(radius)

b)

radius = circle(50)

c)

circle(radius)

radius = 50

d)

radius = 50

circle(50)

19.

Can a user’s input control the size of a circle? If so, how?

a)

No, user input is a string.

b)

Yes

circle(user_input=50)

c)

Yes

radius = int(input("Radius: "))

circle(radius)

d)

Yes

radius = input("Radius: ")

circle(radius)

20.

What is the most effective way to draw three circles in a row of different colors?

a)
b)
c)
d)
21.

What will be the output of the following program?

a)

Three circles with radii of 3, 7 and 2.

b)

Three shapes- a triangle (3 sides), a heptagon (7 sides), and a line (2 sides).

c)

Three shapes- a triangle (3 sides), a pentagon (5 sides), and a heptagon (7 sides).

d)

Two shapes- a triangle (3 sides) and a pentagon (5 sides).

22.

What will be the radii of the circles drawn from the following code?

a)

10, 20, 30, 40, 50

b)

10, 15, 20, 25, 30, 35, 40, 45, 50, 55

c)

10, 55, 10

d)

10, 20, 30, 40, 50, 55

23.

Which command will Tracy perform when given the following code?

a)

forward(200)

b)

backward(200)

c)

forward(201)

d)

backward(201)

24.

Which command will Tracy perform when given the following code?

a)

forward(10)

b)

backward(10)

c)

backward(10)

circle(10)

d)

circle(10)

25.

What will be the output of the following code?

a)

5 circles in a row

b)

4 circles in a row

c)

A slinky with 5 circles

d)

An infinite loop will occur

26.

What is the difference between a binary operator and a unary operator?

a)

A computer can use binary operators, but it cannot use unary operators.

b)

A unary operator needs two things, while a binary operator only needs one.

c)

A binary operator needs two things, while a unary operator only needs one.

d)

Binary operators are used for arithmetic expressions, while unary operators are for strings.

27.

On which line of code will Python error?

a)

Line 1

b)

Line 2

c)

Line 3

d)

Line 4

28.

In what order should these statements be executed in order to get input from the user and print out the result?

a)

A, B, C, D

b)

B, C, A, D

c)

A, C, D, B

d)

C, B, A, D

29.

What is the output of the following program? Assume the user enters “Florence”, then “Fernandez”.

a)

Fernandez Florence

b)

Florence

Fernandez

c)

FlorenceFernandez

d)

Florence Fernandez

30.

Which of the following statements is true about print statements?

a)

I, IV

b)

II, III

c)

I, II, IV

d)

I, III, IV

31.

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?

a)

user_age

b)

uSeRaGe

c)

user!age!

d)

1user_age

32.

Which of the following choices is NOT a Python variable type?

a)

int

b)

str

c)

float

d)

number

33.

Choose the correct declaration of a float variable with the value 3.14.

a)

pi = “3.14”

b)

pi = int(3.14)

c)

pi = 3.14

d)

float pi = 3.14

34.

What is the final result of the expression 4 + 5 * 3?

a)

27

b)

12

c)

21

d)

19

35.

What is the final result of the expression 7 / 3 + 6?

a)

0

b)

8.33333333333

c)

8

d)

0.777777777778

36.

Choose the print statement below that will cause an error. Assume that num has the value 6, and namehas the value Isabella.

a)

print name + ":"

print num

b)

print name + " wants " + "num " + "candies”

c)

print name + ": " + str(num)

d)

print name + ": " + num

37.

Which one of the statements below will cause an error?

a)

ans = “hi” * 8

b)

ans = “hi” + 9

c)

ans = “hi” + “hi” + “hi”

d)

ans = (“a” * 4) + “b”

38.

What does the following program print?

a)

<type 'str'>

b)

<type 'int'>

c)

<type 'float'>

d)

The program crashes and doesn’t print anything.

39.

Suppose you have a variable defined a = "4". What is the variable type of a?

str int float number

a)

str

b)

int

c)

float

d)

number

40.

Choose the option that correctly prints out the variable(s).

a)
b)
c)
d)
41.

What kind of data does a float variable contain?

a)

Whole numbers

b)

Words

c)

Numbers that can have decimal components

d)

A float is not a Python variable type

42.

What does the following code print?

a)

3.4

4.4

b)

3

4.4

c)

3

4

d)

The code causes an error

43.

Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?

a)

num = str(input(“Enter a number: “))

b)

num = number(input(“Enter a number: “))

c)

num = input(“Enter a number: “)

d)

num = int(input(“Enter a number: “))

44.

What is the final result of the expression 2**3?

a)

6

b)

8

c)

2

d)

That is not a valid Python expression.

45.

What is the character that in-line Python comments begin with?

a)

#

b)

%

c)

-

d)

46.

What will print to the screen when the following program is run?

a)

5

b)

True

c)

<type ‘int’>

d)

<type ‘bool’>

47.

What will print to the screen when the following program is run?

a)

5

b)

False

c)

<type ‘int’>

d)

<type ‘bool’>

48.

What will be the output of this program?

a)

0

b)

5

c)

True

d)

Nothing will print

49.

What will be the output of this program?

a)

0

b)

5

c)

True

d)

Nothing will print

50.

What will be the output of this program?

a)

5

5

b)

-5

c)

5

-5

d)

Nothing will print

51.

What will be the output of this program?

a)

5

b)

5

7

c)

5

7

8

d)

5

8

52.

What will the following program print when run?

a)

Issue Driver’s License

b)

Almost eligible for Driver’s License

c)

No requirements met

d)

Nothing will print

53.

What will the following program print when run?

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

54.

What will the following program print when run?

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

55.

What does this program print?

a)

You are below average height

b)

You are above average height

c)

You are average height

d)

You are below average height

You are above average height

56.

What does this program print?

a)

You are below average height

b)

You are above average height

c)

You are average height

d)

You are below average height You are above average height

57.

What does this program print?

a)

But green is the color of grass! Blue is the best But yellow is the color of school buses!

b)

But green is the color of grass!

c)

But green is the color of grass!

I like red, too!

Blue is the best But yellow is the color of school buses!

d)

Blue is the best

58.

What does this program print?

a)

Must be yellow

b)

Must be blue

I like purple

Blue is the best

c)

Must be blue

d)

Blue is the best

59.

How would you round the number held in the variable pi to 3.14?

pi = 3.14159265

a)

round(pi)

b)

round(pi, 3)

c)

round(3, pi)

d)

round(pi, 2)

60.

Why should you use round when you compare two numbers that have type float?

a)

If you don’t, Python will only compare the whole part and discard the decimal part.

b)

You don’t have to, but it’s good style. All of the comparisons will still work out the same way.

c)

Sometimes numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round in order to make sure both numbers are rounded the same way.

d)

You should always use round when you compare two numbers, even if they are of type int.

61.

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

a)
b)
c)
d)
62.

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

a)
b)
c)
d)
63.

What is the value of num when this loop completes?

a)

2

b)

8

c)

12

d)

20

64.

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):

65.

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):

66.

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

67.

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

a)
b)
c)
d)
68.

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

a)
b)
c)
d)
69.

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

70.

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

71.

What is the value of sum when this loop completes?

a)

8

b)

9

c)

20

d)

0

72.

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

a)

100

0

-75

-125

-150

b)

-150

c)

-175

d)

175

73.

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

74.

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

75.

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)

On line 3

b)

On line 5

c)

On line 7

d)

On line 9

76.

Which of the following programs will NOT cause an error?

a)
b)
c)
d)
77.

Which of the programs below will print the following output?

I would like a green balloon.

a)
b)
c)
d)
78.

What will be the output of the following program?

a)

12

b)

code

c)

4

d)

codecodecode

79.

What will be the output of the following program?

a)

Tracy

b)

hello Turtle

c)

Turtle

d)

hello Tracy

80.

What would this program print?

a)

It doesn’t print anything

b)

<>

c)

<><><><>

d)

<><><>

81.

Consider the following functions. Which for loop would print

Fizz

Fizz

a)

for i in range(6): fn_b(i+1)

b)

for i in range(6): fn_a(i) fn_b(i)

c)

for i in range(6): fn_a(i)

d)

for i in range(6): fn_b(i)

82.

What would this program print?

a)

Original Point: 16, 20

Midpoint from Origin: 8, 10

Point: 16, 20

b)

Original Point: 12, 14

Midpoint from Origin: 6, 7

Point: 12, 14

c)

Original Point: 16, 20

Midpoint from Origin: 8, 10

Point: 12, 14

d)

Original Point: 12, 14

Midpoint from Origin: 6, 7

Point: 16, 20

83.

Which of the following options is NOT a valid Python function definition?

a)
b)
c)
d)
84.

What is the output of this program? Assume the user enters “kipp52”, then “baseball45”.

a)
b)
c)
d)
85.

What will be printed when the program below is run?

a)

12

b)

24

c)

50

d)

66

86.

What is the purpose of exceptions?

a)

To indicate that something has gone wrong, and the program does not know how to continue

b)

To point out when the programmer has written exceptionally good code

c)

To tell the user that he/she has given bad data, such as a negative number instead of a positive number

d)

To allow the programmer to write bad code, but have it still work

87.

What will be printed to the screen if the inputs given to the program below are 1.2, -4, hi, 5 ?

a)
b)
c)
d)
88.

Which of the following inputs to the program below would return a print statement containing Your number:

a)

Four

b)

5

c)

3.0

d)

*

89.

What line of code should be written after the function definition to add two single digit values and print the sum?

a)

print get_single_digit() + get_single_digit()

b)

return get_single_digit() + get_single_digit()

c)

print get_single_digit(4) + get_single_digit(5)

d)

print get_single_digit()++

90.

Why do programmers use try and except statements when their code might throw an exception?

a)

So that the programmer can disregard the exception and do what he/she wants anyways

b)

Because Python requires it

c)

To handle exceptions gracefully and either handle the error or print out a useful error message.

d)

Exceptions only are thrown when there are try and exceptstatements. Otherwise, the program will just fail and the programmer will have no idea why it failed.

91.

What kind of data structure is user_data in the following declaration?

user_data = ("TJ", 24, "artLover123")

a)

Tuple

b)

List

c)

String

d)

2d List

92.

What kind of data structure is user_data in the following declaration?

user_data = ["TJ", 24, "artLover123"]

a)

Tuple

b)

List

c)

String

d)

2d List

93.

Which of the following lines of code will cause an error? Use the following definition of ages:

ages = (12, 5, 8)

a)

ages = ages + (1, 3, 5)

b)

print ages[2]

c)

ages = ages[2:]

d)

ages[0] = 3

94.

What does this code snippet print?

fruit = ["b", "n", "n"]

print "a".join(fruit)

a)

bnn

b)

ba na na

c)

banan

d)

banana

95.

What is the value of num after this code runs?

shapes = ["triangle", "square", "hexagon", "circle", "pentagon"]

num = len(shapes)

a)

0

b)

4

c)

5

d)

35

96.

What does this program print?

a)

My favorite animal is a dog or penguin

b)

My favorite animal is a penguin or chipmunk

c)

My favorite animal is a dog penguin chipmunk

d)

My favorite animal is a dog or chipmunk

97.

Which of the following data structures is immutable?

a)

Tuple

b)

List

c)

Dictionary

d)

2d List

98.

What does this program print?

a)

[48, 56, 64, 65, [60, 61, 62]]

b)

[48, 56, 60, 61, 62, 64, 65]

c)

[48, 56, 64, 65, 60, 61, 62]

d)

The program will error.

99.

How many times does this program print That's a large class!?

a)

0

b)

1

c)

4

d)

6

100.

What would the following program print to the screen when run?

a)

7

0

0

d

n

o

B

b)

0

0

7

B

o

n

d

c)

B

o

n

d

0

0

7

d)

700donB

101.

Given the following list: my_list = ["s", "Z", "e", "c", "c", "e", "r", "h", "e", "p", "t"] which program below would give the following output:

a)
b)
c)
d)
102.

Which values entered into ‘my_list’ would print a value of ‘-1’ after the program has run?

a)

5, -10, 6

b)

-10, -5, 6

c)

-5, 10, 6

d)

-5, 0, 10, 6

103.

Which of the following programs would produce the following output:

a)
b)
c)
d)
104.

Which of the following programs would alter my_list to consist of the following:

[‘red’, ‘green’, ‘blue’, ‘orange’, ‘yellow’]

a)

my_list = ['red', 'green', 'blue', 'orange']

my_list.append('yellow')

b)

my_list = ['red', 'green', 'blue', 'orange']

my_list.extend('yellow')

c)

my_list = ['red', 'green', 'blue', 'orange']

my_list.replace('yellow')

d)

my_list = ['red', 'green', 'blue', 'orange']

my_list.add('yellow')

105.

What will be the output of the following program?

a)

[1, 2, 3, 4, 5, 5, 5, 5]

b)

[1, 2, 3, 4, 5]

c)

[1, 2, 3, 4, 6, 7, 8, 9]

d)

[1, 2, 3, 4, 5, 6, 7, 8]

106.

Eliza will wear a coat if it is raining or if it is less than 50° F outside. Otherwise, Eliza will leave her coat at home.

In which of the following cases will Eliza leave her coat at home?

a)

It is raining and 30°F

b)

It is raining and 55°F

c)

It is not raining and 45°F

d)

It is not raining and 50°F

107.

Tracy the Turtle is given the following instructions:

repeat 2 times:

forward 100 units

turn left 120 degrees

forward 100 units

turn left 60 degrees

Given Tracy’s starting point below, what will be the result of running this program code?

a)
b)
c)
d)
108.

Which of the following describes a task effectively broken into smaller parts?

I. Writing a book by brainstorming, making an outline, and drafting the first chapter

II. Comparing two different cameras

III. Using your phone’s calculator

a)

I only

b)

I and III

c)

II only

d)

I, II and III

109.

Evaluate the mathematical expression: 10 - 6 x (4 - 2) / 2 + 5.

a)

9

b)

10

c)

13

d)

17

110.

If x represents the area of the number line colored blue, which inequality accurately reflects the value of x?

a)

x < 5

b)

x > 5

c)

x ≥ 5

d)

x ≤ 5

111.

What is the result of running this program code?

a)

3

b)

6

c)

10

d)

The program results in an infinite loop

112.

What is the difference between a for loop and a while loop?

a)

A for loop repeats commands a specific number of times and a while loop repeats until a condition becomes false.

b)

A for loop is used to make decisions between two options and a while loop is used to make decisions between 3 options or more.

c)

A for loop is used when the variable is less than 10 and a while loop is used when the variable is 10 or greater.

d)

A for loop is used when we only need to meet one condition and a while loop is used when there are two or more conditions.

113.

What would the output of the following code be?

x = "Tracy"

print x*5

a)

Tracy5

b)

Tracy Tracy Tracy Tracy Tracy

c)

TracyTracyTracyTracyTracy

d)

x5

114.

How many times would the phrase ‘codeHS’ be printed in the following scenario:

a)

2 times

b)

6 times

c)

8 times

d)

16 times

115.

What is the total forward distance moved when the code below is run?

a)

20

b)

50

c)

100

d)

200

116.

What is the type of the variable x?

x = 5

a)

float

b)

int

c)

str

d)

bool

117.

What would be printed to the screen when the following program is run?

a)

2

b)

3

c)

5

d)

6

118.

What would be the output of the following code?

a)

Yes

b)

No

c)

Maybe

d)

No output

119.

What would be the output of the following code?

a)

[“yellow”, “red”, “orange”, “green”, “blue”]

b)

[“red”, “green”, “blue”, “yellow”, “orange”]

c)

[“yellow”, “blue”, “green”, “red”, “orange”]

d)

[“blue”, “green”, “orange”, “red”, “yellow”]

120.

What would be the output of the following code?

a)

Tracy

Tracy

Turtle

b)

TracyTracy

Turtle

TracyTracy

Turtle

c)

TracyTracy

Turtle

d)

Tracy

Turtle

121.

What will the value of sum be after the following code runs?

a)

6

b)

12

c)

24

d)

0

122.

Which of the following operations will cause an error?

a)
b)
c)
d)
123.

What list is produced using the following list comprehension?

a)

['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w']

b)

[‘w’, ‘o’, ‘r’, ‘d’]

c)

['b', 'u', 't', 't', 'e', 'r', 'f', 'l', 'y']

d)

['butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly']

124.

What function would you use to get the position of a character in a string?

a)

len

b)

strip

c)

remove

d)

find

125.

Given the following 2D list, which of the following expressions would get the element “cucumber”?

a)

foods[2][1]

b)

foods[1][0]

c)

foods[0][2]

d)

foods[1][1]

126.

What is the value of the list after this program runs?

a)

[‘Mon’, ‘Tues’, ‘Wed’, ‘Thurs’, ‘Fri’, ‘Sat’, ‘Sun’]

b)

[‘Mon’, ‘Tues’, ‘Wed’, ‘Thurs’, ‘Fri’, [‘Sat’, ‘Sun’]]

c)

[‘Fri’, ‘Thurs’, ‘Wed’, ‘Tues’, ‘Mon’, ‘Sat’, ‘Sun’]

d)

[‘Fri’, ‘Thurs’, ‘Wed’, ‘Tues’, ‘Mon’, [‘Sat’, ‘Sun’]]

127.

What is the result of word[-3] if word = “chalkboard”?

a)

o

b)

l

c)

a

d)

r

128.

What is wrong with the following function?

a)

Only one parameter can have a default value given

b)

Any parameters that don’t have default values must come before any parameters that do have default values

c)

Default parameters must be the same type for every parameter

d)

There is nothing wrong with the function

129.

Which of the following boolean expressions would make the while loop find the first animal in the list whose length is longer than 8?

a)

len(animals[cur]) <= 8

b)

len(cur) <= 8

c)

len(animals) <= 8

d)

animals[cur].len <= 8

130.

The following snippet is from a program that asks the user what he/she wants to order. The user’s input is stored in the variable item_ordered. If the user enters 3, what will the following code snippet print?

a)

You have ordered the following item: 3

b)

You have ordered the following item: three

c)

You have ordered the following item:

I’m sorry. You have entered an invalid item

d)

I’m sorry. You have entered an invalid item