wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Midterm prep 10 gr

Total questions: 45

Worksheet time: 43mins

Name
Class
Date
1.

Which code means not equal to?

a)

==

b)

<=

c)

>

d)

!=

2.

Which of the following is NOT a Comparison Operator?

a)

<=

b)

==

c)

=

d)

!=

3.

Which of the following is NOT a Boolean Statement?

a)

name == "duck"

b)

8 <= 12

c)

num = int(Input("Pick a number.")

d)

total > 0

4.

Which booleans have a value of True?

a)

12 - 3 == 9

b)

30 <= 25

c)

17 != 11 + 6

d)

15 / 5 == 3.0

5.

Which of the following are valid values for a boolean in Python?

Select ALL that apply.

a)

True

b)

false

c)

0

d)

False

e)

1

6.

What is the final value for total?

a)

6

b)

4

c)

7

d)

9

7.

Which lines of code will be skipped when the program is run?

a)

4, 7, 8

b)

4

c)

3, 7, 8

d)

7, 8

8.

What is the truth value for the compound Boolean statement?

5 == 2 + 3 or 7 > 8

a)

True

b)

False

c)

No Value

9.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
10.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
11.
Which statement will check to see if a is equal to b?
a)

if a equal b

b)
if a = b:
c)
if a != b:
d)
if a == b:
12.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

13.

What is the value of the expression 100 / 25?

a)

4

b)

4.0

c)

"4.0"

d)

'4.0'

14.

What is the output of the following code :


print 9//2

a)

4.5

b)

4.0

c)

4

d)

3

15.

What is the answer of this expression, 22 % 3 is?

a)

7

b)

1

c)

0

d)

5

16.

The program above:

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

17.

How many times the following loop will execute:

i = 1

while True:

print(i)

i += 2

a)

0

b)

2,4,6,8,..................

c)

1,3,5,7,9,.............

d)

1,2,4,6,8......................

18.

i = 1

while True:

if i%7 == 0:

break

print(i)

i += 1

a)

123456

b)

1234567

c)

error

d)

none

19.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

20.

Which of the following programs prints ten lines?

a)

for i in range(10):

print("hi")

b)

for i = 1 to 10:

print("hi")

c)

for i in 1 - 10:

print("hi")

d)

for i from 0 to 9:

print("hi")

21.

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)

22.
a)
b)
c)
d)

1,2,3,4

23.

One of the following functions is not used with Python String

a)

Split

b)

Remove

c)

print

d)

Replace

24.

Choose the correct code to print line of 10 stars using repetition operation:

a)

print("**********")

b)

print("*"*10)

c)

print("*"^10)

d)

print("*"+10)

25.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

26.

The correct syntax for converting the string x to uppercase is :

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

27.

The correct syntax for converting the string myname to lowercase is :

a)

myNAME.lower[ ]

b)

myname.lower( )

c)

myname.upper( )

d)

myname_lower(12 )

28.

Let x= "Python", the output of

print(x[0])

print(x[1])

print(x[2])

a)

PYT

b)

P

y

t

c)

T

h

o

d)

n

oh

29.

Let x= "Python", the output of

print(x[0])

print(x[-1])

print(x[-2])

a)

P

N

O

b)

p

O

n

c)

t

h

y

d)

P

n

o

30.
What will the output be from the following code?
print("Hello" + "world" + "today")
a)
Helloworldtoday
b)
Hello world today
c)
"Hello" "world" "today"
d)
SyntaxError
31.
Which is the most appropriate data type for: "13th December"
a)
Float
b)
Boolean
c)
Integer
d)
String
32.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

is

d)

in

33.

data = "No Way!"


The expression len(data) evaluates to:

a)

8

b)

7

c)

6

34.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

35.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

36.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

37.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

38.
What is the output when we execute list(“hello”)?
a)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b)
 [‘hello’] 
c)
[‘llo’]
d)
 [‘olleh’]
39.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

mariana_islands[0] = 'Guam'

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Guam', 'Tinian', 'Rota']

c)

['Saipan', 'Tinian', 'Rota', 'Guam']

d)

['Guam', 'Saipan', 'Tinian', 'Rota']

40.

What is the output of the following nested loop?

a)

10 Chair

10 Table

20 Chair

20 Table

b)

10 Chair

10 Table

41.

Write a Python program using nested loops to print a right-angled triangle pattern.

a)

for i in range(1, 6): for j in range(i): print('*', end='') print()

b)

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

c)

for j in range(1, 6):

d)

for i in range(1, 5):

42.

How many times will the inner loop run in the following nested for loop? for i in range(5): for j in range(3): print(i, j)

a)

5

b)

15

c)

8

d)

3

43.

What is the output of the following nested for loop in Python? for i in range(3): for j in range(2): print(i, j)

a)

The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 2 2

b)

The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 3 0

c)

The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 2 1

d)

The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 3 1

44.

What will be the output of the following nested for loop? for i in range(2, 5): for j in range(1, 3): print(i * j)

a)

2 4 3 6 4 8

b)

1 2 2 4 3 6

c)

2 3 4 5 6

d)

3 6 4 8 5 10

45.

Write a nested for loop in Python to print the following pattern: 1 1 2 1 2 3 1 2 3 4

a)

for i in range(1, 5): for j in range(1, i+1): print(j, end=' ') print()

b)

for i in range(1, 5): for j in range(1, 5): print(j, end=' ') print()

c)

for i in range(1, 5): for j in range(1, i+2): print(j, end=' ') print()

d)

for i in range(1, 5): for j in range(1, i): print(j, end=' ') print()