wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python basics 8th grade

Total questions: 25

Worksheet time: 39mins

Name
Class
Date
1.

_____ = 25

print(age)

What should fill the blank to declare a variable age with value 25?

a)

age

b)

int age

c)

int(age)

d)

Age

2.

name = "Python"

print(len(name))

What will this code output?

a)

7

b)

6

c)

Python

d)

5

3.

x = 10

y = 3

print(x _____ y)

What operator should fill the blank to output 13?

a)

+

b)

-

c)

*

d)

/

4.

score = 85

if score _____ 60:

print("Pass")

What should fill the blank?

a)

!=

b)

==

c)

>

d)

<

5.

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

print(fruits[_____])

What index should fill the blank to print "apple"?

a)

3

b)

2

c)

1

d)

0

6.

for i in range(_____):

print(i)


What should fill the blank to print numbers 0, 1, 2?

a)

2

b)

3

c)

4

d)

1

7.

text = "hello"
print(text._____)

What method converts the string to uppercase?

a)

UPPER()

b)

upper()

c)

toUpper()

d)

uppercase()

8.

a = 5

b = 5

print(a _____ b)

What operator checks if a equals b?

a)

=

b)

===

c)

!=

d)

==

9.

What should fill the blank to loop 3 times (0, 1, 2)?

a)

==

b)

<=

c)

>

d)

<

10.

x = True

y = False

print(x _____ y)

What operator returns True if at least one value is True?

a)

and

b)

not

c)

or

d)

xor

11.

What method adds 50 to the end of the list?

a)

add

b)

insert

c)

append

d)

push

12.

What keyword should fill the blank?

a)

else if

b)

elseif

c)

if

d)

elif

13.

word = "Python"

print(word[_____])

What should fill the blank to print "thon"?

a)

2:6

b)

1:5

c)

2:

d)

3:

14.

What should fill the blank to print: 2, 3, 4, 5?

a)

6

b)

5

c)

7

d)

4

15.

What operators should fill the blanks?

a)

>, <

b)

==, ==

c)

>=, <=

d)

>, >

16.

colors = ["red", "blue", "green", ...]

print(colors[_____])

What index prints the last element?

a)

3

b)

-1

c)

2

d)

last

17.

What operator should fill the blank?

a)

//

b)

/

c)

*

d)

%

18.

message = "Hello World"

print(message._____)

What method converts to lowercase?

a)

lowercase()

b)

toLower()

c)

lower()

d)

LOWER()

19.

What should fill the blank to sum all numbers?

a)

=+

b)

+=

c)

==

d)

= total +

20.

What operator should fill the blank?

a)

not

b)

!

c)

NOT

d)

and

21.

What condition should fill the blank to get only numbers divisible by 10?

4 lines
22.

What condition counts the letter 'g'?

4 lines
23.

What line should fill the blank to prevent an infinite loop?

4 lines
24.

What condition finds the maximum value?

4 lines
25.

What condition separates even and odd numbers?

4 lines