wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Sp25 Python Programming Final, Part 1

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What does forward(100) do in Turtle Graphics?

a)

Turns the turtle 100 degrees

b)

Moves the turtle forward by 100 pixels

c)

Sets the turtle’s speed

d)

Draws a circle with radius 100

2.

Which function is used to change the turtle's direction?

a)

move()

b)

turn()

c)

left()

d)

forward()

3.

What happens if you use a negative value in forward(-50)?

a)

Error

b)

Moves backward

c)

Turns 180 degrees

d)

Clears the screen

4.

Which command sets the turtle’s pen color?

a)

color("blue")

b)

setcolor("blue")

c)

changecolor("blue")

d)

color.pens("blue")

5.

What does penup() do?

a)

Lifts the turtle off the screen

b)

Increases pen size

c)

Stops the turtle from drawing lines

d)

Moves the turtle faster

6.

What symbol is used to make a comment in Python?

a)

//

b)

**

c)

#

d)
7.

What does input() do?

a)

Displays output on the screen

b)

Pauses the program

c)

Takes user input

d)

Defines a function

8.

What is the output of:

print("5" + "2")

a)

7

b)

52

9.

What type of value does input() return?

a)

Integer

b)

Float

c)

Boolean

d)

String

10.

Which function converts a string to an integer?

a)

str()

b)

toInt()

c)

int()

d)

number()

11.

What keyword begins a conditional statement?

a)

if

b)

when

c)

condition

d)

check

12.

Given the Python code shown, what will be printed?

a)

Yes

b)

No

c)

10 > 5

d)

Error

13.

Which operator represents "not equal"?

a)

!=

b)

==

c)

=

d)

<>

14.

What is the purpose of elif?

a)

Ends the program

b)

Declares a loop

c)

Checks another condition

d)

Comments code

15.

Given the following Python code:

x = 3

print(x)

What will be printed?

a)

3

b)

x

c)

None

d)

Error

16.

Which logical operator means “and”?

a)

&&

b)

and

c)

&

d)

also

17.

What does this condition evaluate to?

5 > 3 and 2 > 4

a)

True

b)

False

c)

Error

18.

What type of loop is best for repeating something a set number of times?

a)

while

b)

repeat

c)

for

d)

until

19.

How many times does this loop run?

a)

4

b)

5

c)

6

d)

Infinite

20.

What is the output of the pictured code?

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

0 1 2 3 4

21.

What keyword stops a loop early?

a)

stop

b)

skip

c)

break

d)

exit

22.

What does continue do?

a)

Ends the loop

b)

Skips current iteration

c)

Pauses the loop

d)

Repeats previous iteration

23.

What does

range(2, 10, 2)

return?

a)

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

b)

[2, 4, 6, 8]

c)

[2, 5, 8]

d)

[2, 10, 2]

24.

What kind of loop could result in an infinite loop if not careful?

a)

for

b)

while

c)

both

d)

neither

25.

What keyword is used to define a function?

a)

func

b)

def

c)

define

d)

lambda

26.

What is wrong with this function?

a)

Missing colon

b)

Wrong indent

c)

Too many arguments

d)

Wrong print syntax

27.

How do you call a function named add()?

a)

run add

b)

call add

c)

add()

28.

What is the purpose of try and except?

a)

Test values

b)

Handle errors

c)

Repeat loops

d)

Define strings

29.

What is printed?

a)

5

b)

6

c)

8

d)

double

30.

Which part of this code runs when an error occurs?

a)

try block

b)

except block

c)

finally block

d)

error handling block

31.

What does return do in a function?

a)

Ends the function and sends a value

b)

Loops again

c)

Skips errors

d)

Stops the program

32.

What is the index of "o" in "hello"?

a)

A) 1

b)

B) 2

c)

C) 3

d)

D) 4

33.

What does "Python".lower() return?

a)

python

b)

PYTHON

c)

Python

d)

error

34.

What is the result of the following Python expression? "cat" + "dog"

a)

catdog

b)

cat dog

c)

cat+dog

d)

Error

35.

Which method gets part of a string?

a)

slice()

b)

get()

c)

sub()

d)

indexing with [ ]

36.

What does "hi"[1] return?

a)

h

b)

i

c)

hi

d)

Error

37.

Which method removes spaces from both ends of a string?

a)

trim()

b)

strip()

c)

split()

d)

clean()

38.

What data structure is created by [ ]?

a)

Dictionary

b)

String

c)

List

d)

Tuple

39.

What does append() do to a list?

a)

Removes items

b)

Adds item to end

c)

Sorts list

d)

Reverses list

40.

What does this print? Python numbers = [2, 4, 6] print(numbers[1])

a)

2

b)

4

c)

6

d)

1

41.

Which method removes an item by index?

(a)  

42.

How do you create a dictionary?

a)

()

b)

[]

c)

{}

d)

<>

43.

What will this print?

Python info = {"name": "Sam", "age": 16}

print(info["age"])

a)

Sam

b)

16

c)

age

d)

info

44.

What is the index of the first item in a list?

a)

1

b)

0

c)

-1

d)

Depends

45.

Which function gives the length of a list?

a)

size()

b)

count()

c)

len()

d)

range()

46.

What does this code print?

Python fruits = ["apple", "banana"]

fruits[1] = "pear"

print(fruits)

a)

A) ["apple", "banana"]

b)

B) ["pear", "banana"]

c)

C) ["apple", "pear"]

d)

D) Error

47.

What is a tuple?

a)

A) A list that changes

b)

B) A loop variable

c)

C) A string

d)

D) An immutable list

48.

48. A tuple is defined as:

a)

A mutable sequence of elements

b)

An immutable sequence of elements

c)

A collection of key-value pairs

d)

A set of unique elements

49.

Which structure uses key-value pairs?

a)

List

b)

Set

c)

Dictionary

d)

Tuple

50.

What will this print?

Python colors = ("red", "green", "blue")

print(colors[2])

a)

green

b)

red

c)

blue

d)

Error