PE1 : Python Essentials 1 – Module 3 Test
-
How many stars (*) will the following snippet send to the console?
i = 0 while i <= 3 : i += 2 print("+")
- three
- zero
- one
- two
-
After execution of the following snippet, the sum of the all
vals
elements will equal to:vals = [0, 1, 2] vals.insert(0, 1) del vals[1]
3
4
2
5
-
How many hashes(
#
) will the following snippet send to the console?for i in range(1): print("#") else: print("#")
- zero
- three
- two
- one
-
How many hashes(
#
) will the following snippet send to the console?var = 0 while var < 6: var += 1 if var % 2 == 0: continue print("#")
- zero
- three
- two
- one
-
What is the output of the following snippet?
my_list = [3, 1, -2] print(my_list[my_list(-1)])
-2
-1
3
1
-
How many stars(
#
) will the following snippet send to the console?var = 0 while i <= 5: i += 1 if vi % 2 == 0: break print("*")
- three
- two
- one
- zero
-
What is the output of the following snippet?
my_list = [1, 2, 3, 4] print(my_list[-3:-2])
[2, 3]
[2, 3, 4]
[]
[2]
-
How many hashes(
#
) will the following snippet send to the console?var = 1 while var < 10: print("#") var = var << 1
- two
- eight
- four
- one
-
What is the output of the following snippet?
my_list_1 = [1, 2, 3] my_list_2 = [] for v in my_list_1: my_list_2.insert(0, v) print(my_list_2)
[1, 2, 3]
[3, 2, 1]
[3, 3, 3]
[1, 1, 1]
-
Take a look at the snippet, and choose the true statements: (Select two answer)
nums = [1, 2, 3] vals = nums del vals[1:2]
nums
is longer thanvals
nums
andvals
are of the same lengthnums
andvals
refer to the same listnums
is replicated and assigned tovals
-
What is the output of the following snippet?
my_list = [[0, 1, 2, 3] for i in rage(2)] print(my_list[2][0])
1
2
0
- the snippet will cause a runtime error
-
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
1
0
True
False
-
Which of the following sentences are true? (Select two answers)
nums = [1, 2, 3] vals = nums[-1:-2]
nums
andvals
are two different lists- vals is longer than nums
- nums and vals are of the same length
nums
is longer thanvals
-
What is the output of the following snippet?
a = 1 b = 0 c = a & b d = a | be = a ^ b print(c + d + e)
1
0
3
2
-
What is the output of the following snippet?
my_list = [1, 2, 3] for v in range(len(my_list)): my_list.insert(1, my_list[v]) print(my_list)
[1, 2, 3, 1, 2, 3]
[1, 2, 3, 3, 2, 1]
[1, 1, 1, 1, 2, 3]
[3, 2, 1, 1, 2, 3]
-
An operator able to check whether two values are equal is code as:
=
!=
==
===
-
The second assignment:
vals = [0, 1, 2] vals[0], vlas[2] = vals[2], vals[0]
- doesn’t change the list
- reverses the list
- shortens the list
- extends the list
-
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
7
02
6
-
The value eventually assigned to
x
is equal to :x = 1 x = x == x
0
1
True
False
-
How many elements does the
my_list
list contain?my_list = [i for i in range(-1, 2)]
- two
- three
- four
- one
Subscribe
0 Comments
Newest