Font size
WorksheetsMidterm prep 10 gr
Total questions: 45
Worksheet time: 43mins
Which code means not equal to?
==
<=
>
!=
Which of the following is NOT a Comparison Operator?
<=
==
=
!=
Which of the following is NOT a Boolean Statement?
name == "duck"
8 <= 12
num = int(Input("Pick a number.")
total > 0
Which booleans have a value of True?
12 - 3 == 9
30 <= 25
17 != 11 + 6
15 / 5 == 3.0
Which of the following are valid values for a boolean in Python?
Select ALL that apply.
True
false
0
False
1
What is the final value for total?
6
4
7
9
Which lines of code will be skipped when the program is run?
4, 7, 8
4
3, 7, 8
7, 8
What is the truth value for the compound Boolean statement?
5 == 2 + 3 or 7 > 8
True
False
No Value
if a equal b
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
What is the value of the expression 100 / 25?
4
4.0
"4.0"
'4.0'
What is the output of the following code :
print 9//2
4.5
4.0
4
3
What is the answer of this expression, 22 % 3 is?
7
1
0
5
The program above:
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
How many times the following loop will execute:
i = 1
while True:
print(i)
i += 2
0
2,4,6,8,..................
1,3,5,7,9,.............
1,2,4,6,8......................
i = 1
while True:
if i%7 == 0:
break
print(i)
i += 1
123456
1234567
error
none
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
Which of the following programs prints ten lines?
for i in range(10):
print("hi")
for i = 1 to 10:
print("hi")
for i in 1 - 10:
print("hi")
for i from 0 to 9:
print("hi")
Which of the following for loops would print the following numbers?
3
5
7
9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
1,2,3,4
One of the following functions is not used with Python String
Split
Remove
Replace
Choose the correct code to print line of 10 stars using repetition operation:
print("**********")
print("*"*10)
print("*"^10)
print("*"+10)
The correct syntax of the len function for string x:
x.len()
len[x]
LEN[]
len(x)
The correct syntax for converting the string x to uppercase is :
X.upper()
upper(x)
x.UPPER[ ]
x.upper()
The correct syntax for converting the string myname to lowercase is :
myNAME.lower[ ]
myname.lower( )
myname.upper( )
myname_lower(12 )
Let x= "Python", the output of
print(x[0])
print(x[1])
print(x[2])
PYT
P
y
t
T
h
o
n
oh
Let x= "Python", the output of
print(x[0])
print(x[-1])
print(x[-2])
P
N
O
p
O
n
t
h
y
P
n
o
print("Hello" + "world" + "today")
Which operator returns True if target string is somewhere in the search string; otherwise it returns False.
==
!=
is
in
data = "No Way!"
The expression len(data) evaluates to:
8
7
6
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
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"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
What is the output of program below?
mariana_islands = ['Saipan', 'Tinian', 'Rota']
mariana_islands[0] = 'Guam'
print(mariana_islands)
['Saipan', 'Tinian', 'Rota']
['Guam', 'Tinian', 'Rota']
['Saipan', 'Tinian', 'Rota', 'Guam']
['Guam', 'Saipan', 'Tinian', 'Rota']
What is the output of the following nested loop?
10 Chair
10 Table
20 Chair
20 Table
10 Chair
10 Table
Write a Python program using nested loops to print a right-angled triangle pattern.
for i in range(1, 6): for j in range(i): print('*', end='') print()
for i in range(5, 1, -1):
for j in range(1, 6):
for i in range(1, 5):
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)
5
15
8
3
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)
The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 2 2
The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 3 0
The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 2 1
The output will be: 0 0, 0 1, 1 0, 1 1, 2 0, 3 1
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)
2 4 3 6 4 8
1 2 2 4 3 6
2 3 4 5 6
3 6 4 8 5 10
Write a nested for loop in Python to print the following pattern: 1 1 2 1 2 3 1 2 3 4
for i in range(1, 5): for j in range(1, i+1): print(j, end=' ') print()
for i in range(1, 5): for j in range(1, 5): print(j, end=' ') print()
for i in range(1, 5): for j in range(1, i+2): print(j, end=' ') print()
for i in range(1, 5): for j in range(1, i): print(j, end=' ') print()
