Last Updated on October 18, 2019 by Admin
PCAP – Programming Essentials in Python Quizzes Module 2 Test Answers
-
An operator able to check whether two values are equal is coded as:
- =
- ===
- ==
- !=
-
The value eventually assigned to x is equal to:
x = 1
x = x == x- False
- 1
- True
- 0
-
How many stars will the following snippet send to the console?
i = 0
while i <= 3 :
i += 2
print(“*”)- two
- zero
- one
- three
-
How many stars will the following snippet send to the console?
i = 0
while i <= 5 :
i += 1
if i % 2 == 0:
break
print(“*”)- zero
- one
- two
- three
-
How many hashes will the following snippet send to the console?
for i in range(1):
print(“#”)
else:
print(“#”)- one
- two
- zero
- three
-
How many hashes will the following snippet send to the console?
var = 0
while var < 6:
var += 1
if var % 2 == 0:
continue
print(“#”)- two
- zero
- one
- three
-
How many hashes will the following snippet send to the console?
var = 1
while var < 10:
print(“#”)
var = var << 1- eight
- one
- four
- two
-
What value will be assigned to the x variable?
z = 10
y = 0
x = y < z and z > y or y > z and z < y- 0
- 1
- True
- False
-
What is the output of the following snippet?
a = 1
b = 0
c = a & b
d = a | b
e = a ^ b
print(c + d + e)- 1
- 3
- 2
- 0
-
What is the output of the following snippet?
lst = [3, 1, -2]
print(lst[lst[-1]])- 1
- -2
- 3
- -1
-
What is the output of the following snippet?
lst = [1,2,3,4]
print(lst[-3:-2])- [2,3,4]
- [2]
- []
- [2,3]
-
The second assignment:
vals = [0, 1, 2]
vals[0], vals[2] = vals[2], vals[0]- doesn’t change the list
- extends the list
- shortens the list
- reverses the list
-
After execution of the following snippet, the sum of all vals elements will be equal to:
vals = [0, 1, 2]
vals.insert(0,1)
del vals[1]- 2
- 5
- 3
- 4
-
Take a look at the snippet, and choose the true statement:
nums = [1,2,3]
vals = nums
del vals[1:2]- nums is longer than vals
- vals is longer than nums
- nums and vals are of the same length
- the snippet will cause a runtime error
-
Which of the following sentences is true?
nums = [1,2,3]
vals = nums[-1:-2]- nums is longer than vals
- nums and vals are of the same length
- the snippet will cause a runtime error
- vals is longer than nums
-
What is the output of the following snippet?
l1 = [1,2,3]
l2 = []
for v in l1:
l2.insert(0,v)
print(l2)- [3,2,1]
- [1,2,3]
- [3,3,3]
- [1,1,1]
-
What is the output of the following snippet?
l1 = [1,2,3]
for v in range(len(l1)):
l1.insert(1,l1[v])
print(l1)- [1, 2, 3, 3, 2, 1]
- [1, 2, 3, 1, 2, 3]
- [3, 2, 1, 1, 2, 3]
- [1, 1, 1, 1, 2, 3]
-
How many elements does the L list contain?
L = [i for i in range(-1,2)]
- one
- four
- three
- two
-
What is the output of the following snippet?
T = [[3-i for i in range (3)] for j in range (3)]
s = 0
for i in range(3):
s += T[i][i]
print(s)- 4
- 2
- 7
- 6
-
What is the output of the following snippet?
L = [[0, 1, 2, 3] for i in range(2)]
print(L[2][0])- the snippet will cause a runtime error
- 1
- 2
- 0