wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Their Python Exam

Total questions: 31

Worksheet time: 18mins

Name
Class
Date
1.

The first character in a string is at index 0.

a)

T

b)

F

2.

Which statement Does Not describes a String in Python/Computer Science?

a)

a sequence of characters

b)

a series of 1's and 0's

c)

a set of characters which are represented in/from the ASCII table by holding hte Alt- plus 4 digit decimal number

d)

object existing in four dimensions

3.

Choose the statement that will print the letter "s", given the variable declaration word = "windows"

a)

print(word[-2])

b)

print(word[-1])

c)

print(word[2])

d)

print(word[3])

4.

Which print output is the result of the following code?

a)

"w"

b)

"s"

c)

"o"

d)

""(empty string)

5.

The following code will print "act".


word = "characteristics"

print(word[4:6])

a)

T

b)

F

6.

Which choice will print the second half of the word "Consequences" (uences), given the following variable declaration?


word = "Consequences"

a)

print(word[6:])

b)

print(word[:6])

c)

print(word[1:7])

d)

print(word[7:1])

7.

Choose the correct print output for the following code:

name = "Alton"

print(name[::4]

a)

"Atn"

b)

"lo"

c)

"on"

d)

"An"

8.

Which choice will print the word "tac", given the following variable declaration?

word = "cat"

a)

print(word[::-1])

b)

print(word[::1])

c)

print(word[0:1:2])

d)

print(word[2:1:0])

9.

In the for loop below, the variable "letter" is an arbitrary loop control variable name. Any valid variable name can be used since its value is assigned only within this loop. See code example below:

word = "the word of the day"

for letter in word:

print(letter)

a)

T

b)

F

10.

Which is NOT a start to a string iteration loop, given the following string variable assignment?

word = "health"

a)

for letter in word:

b)

for word in letter:

c)

for ltr in word[1:]:

d)

for part in "health":

11.

Which choice best represents the output of the following code?

student_name = "iteration"

new_word = ""

for letter in student_name[3:]:

new_word += letter

print(new_word)

a)

"ration"

b)

"ite"

c)

"iter"

d)

"ation"

12.

Which choice best represents the output of the following code?

student_name = "iteration"

count = 0

for letter in student_name:

if letter.lower() == "r":

print(count)

count += 1

a)

"2"

b)

"3"

c)

"-4"

d)

"-5"

13.

The .count() string method returns the number of times a a character appears in a string.

a)

T

b)

F

14.

Which string method below returns a boolean datavalue?

a)

.find()

b)

.count()

c)

.isalpha()

d)

while

15.

Which choice will store the length of the given string variable named 'word' in the integer variable named 'x'?

a)

x = len(word)

b)

x = word.len()

c)

x.length(word)

d)

for x in length of word

16.

Which parameter choice passed to the .find() string method will return 0, given the following variable assignment?


word = "Python"

a)

word.find("P")

b)

word.find("y")

c)

word.find("Z")

d)

word.find("o")

17.

The first item in a Python List is located at indexnumber 1.

a)

T

b)

F

18.

Which is an invalid syntax to initialize a Python list named scores?

a)

scores = [97.3, 89.4, 67.0, 91.2]

b)

listdef scores(11, 8, 0, 24, 31, 12, 19)

c)

scores = []

d)

scores = [2, 2, 2, 3, 3, 1, 1]

19.

Which is valid Python code that will print "Red", given the following code?


colors = ["Red", "Blue", "Green", "Yellow"]

a)

print(colors[0])

b)

print(colors[4])

c)

print(colors[3])

d)

print(colors[2])

20.

Choose the item that best completes the following sentence:


"A Python list..."

a)

uses index 1 for the first item in the list.

b)

can contain a mix of strings or numbers as list items.

c)

can contain only all strings or only all numbers as list items - cannot contain a mix.

d)

cannot contain another list - a list in a list.

21.

The .append() method adds items to the end of a list.

a)

T

b)

F

22.

Which code places another integer, 2, to the beginning of the following list?


numbers = [1, 1, 2]

a)

numbers + 2

b)

numbers.add(2)

c)

numbers += 2

d)

numbers.insert(0, 2)

23.

Which best describes the valid Python use best practice of the following days list?

a)

days.append("Wednesday")

b)

days.append(14)

c)

print(days[-1])

d)

all of these

24.

Choose the item that best completes the sentence:


"A Python list..."

a)

cannot be changed after initialization.

b)

can add items of the same datatype only.

c)

can add items to the end of the list using the .append() method or the .insert(-1, datavalue)

d)

always appends to index 0 (zero) - [0] no matter how many items are in the list.

25.

The .insert(index, datavalue) method inserts the datavalue item after the given index value.

a)

T

b)

F

26.

Which code overwrites or replaces the second occurrence of the item datavalue "1" with a "5" in the following list named numbers?

numbers = [1, 1, 0]

a)

numbers[3] = 5

b)

numbers[1] = 5

c)

numbers.append(5)

d)

numbers.insert(2, 5)

27.

Which best describes a valid Python use best practice of the following list named days which contains a human count of 6 items?

a)

days.append("Wednesday")

b)

days.insert(4, "January")

c)

days.append("the day of week")

d)

none of these

28.

Choose the item that best completes the following sentence:


"After using a .insert method on a Python list...

a)

one of the index datavalues gets overwritten.

b)

an error occurs if the inserted object is not of the same type of the other list items.

c)

the length of the list remains the same.

d)

the length of the list increases by 1.

29.

The .pop() method only deletes an item from a list.

a)

T

b)

F

30.

Which code is the best use of Python that deletes the integer, 1, in the following list named numbers?


numbers = [7, 1, 5, 8, 0]

a)

numbers[3] = ""

b)

numbers[2].delete()

c)

del numbers[1]

d)

numbers.remove(2)

31.

Which code is the best use of Python that deletes the integer, 1, in the following list named numbers?


numbers = [7, 1, 5, 8, 0]

a)

numbers[3] = ""

b)

numbers[2].delete()

c)

del numbers[1]

d)

numbers.remove(2)