Log in
Sign up for FREE
arrow_back
Library
Practice Test Python
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
25 questions
Add this activity
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Question 1
1.
What is the output of the following snippet?
tup = (1,2,4,8,3,9,2,5,1)
tup = tup[-3:-1]
tup = tup[-1]
print(tup)
4
2
8
5
1
Question 2
2.
Which of the following lines correctly invoke the function defined below? Select two answers.
def fun(a=1, b, c=0):
# Body of the function
fun()
fun(b=0,a=0)
fun(0,1,2)
fun(b=1)
Question 3
3.
What is the expected behavior of the following program?
foo = (1, 2, 3)
foo.index(1)
The program will not output anything.
The program will cause a ValueError exception.
The program will cause an AttributeError exception.
The program will cause a TypeError exception.
The program will cause a SyntaxError exception.
Question 4
4.
What will be the output of the following snippet?
a = 0
b = 1
c = 0
a = a ^ c
b = b ^ a
c = c ^ b
print(a, b, c)
1 0 0
0 1 1
0 0 1
0 0 0
0 1 0
Question 5
5.
What is the output of the following piece of code if the user enters two lines containing 2 and 16 respectively?
x = float(input())
y = float(input())
print( y** (1 / x))
1.0
0.0
8.0
2.0
4.0
Question 6
6.
An operator able to check whether two values are not equal is:
<>
not ==
!=
=/=
Question 7
7.
What is the output of the following piece of code?
x = 1 % 5 * 1 / 5
print(x)
1
0
0.0
0.2
0.4
Question 8
8.
What is the output of the following snippet?
my_list = [x * x for x in range(6) ]
def fun (1st):
del 1st [1st[2]]
return 1st
print(fun(my_list))
[0, 1, 4, 9 ]
[0, 1, 4, 9, 25, 36]
[0, 1, 4, 9, 25 ]
[0, 1, 4, 16]
Question 9
9.
Take a look at the snippet and choose the true statement:
nums = [1, 2, 3 ]
vals = nums
del vals []
vals is longer than nums
nums is longer than vals
the snippet will cause a syntax error
nums and vals have the same length
Question 10
10.
The result of the following division:
1 // 2
cannot be predicted
is equal to 0.5
is equal to 0
is equal to 0.0
Question 11
11.
What is the output of the following piece of code if the user enters two lines containing 3 and 4 respectively?
x = int(input())
y = int(input())
x = x % y
x = x % y
y = y % x
print(y)
0
2
3
1
Question 12
12.
What is the output of the following snippet?
dd = {"1": "0", "0": "1"}
for x in dd:
print(x, end=" ")
0 0
1 0
0 1
the code is erroneous (the dict object has no vals() method)
Question 13
13.
What is the expected behavior of the following program?
try:
print(5/0)
except (ValueError, ZeroDivisionError):
print("Too bad...")
except:
print("Sorry, something went wrong...")
The program will raise an exception handled by the first except block
The program will cause a ValueError exception and output the following message: Too bad...
The program will cause a ZeroDivisionError exception and output the following message: Too bad...
The program will cause a ValueError exception and output a default error message.
The program will cause a ZeroDivisionError exception and output a default error message.
The program will cause a SyntaxError exception.
Question 14
14.
Which of the following sentences are true about the code?( Select two answers)
nums = [1, 2, 3]
vals = nums
vals = [2, 3, 4]
nums has the same length as vals
vals is longer than nums
nums and vals are different lists
nums and vals are different names of the same list
Question 15
15.
The following snippet:
def func(b, a):
return b ** a
print(func(b=2, 2))
will output None
is erroneous
will output 4
will output 2
Question 16
16.
The value eventually assigned to x is equal to:
x =1
x = x == x
True
1
0
False
Question 17
17.
Take a look at the snippet, and choose the true statements:(Select two answers)
nums = [1, 2, 3 ]
vals = nums
del vals[1:2]
nums is replicated and assigned to vals
nums is longer than vals
nums and vals refer to the same list
nums and vals are of the same length
Question 18
18.
What is the output of the following snippet?
my_list = [3, 1, -2]
print(my_list[-3])
-1
1
-2
3
Question 19
19.
How many stars (*) with the following snippet send to the console?
i = 0
while i <= 5:
i += 2
if i % 2 == 0:
break
print("*")
three
zero
one
two
Question 20
20.
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[2]
3
2
5
4
Question 21
21.
Which of the following statements are true?(Select two answers)
The ** operator uses right-sided binding
Addition precedes multiplication
The result of the / operator is always an integer value
The right argument of the % operator cannot be zero
Question 22
22.
The result of the following division:
1/1
cannot be predicted
is equal to 1.0
cannot be evaluated
is equal to 1
Question 23
23.
Which of the following variable names are illegal? (Select two answers)
true
True
TRUE
and
Question 24
24.
The ** operator:
performs floating-point multiplication
does not exist
performs duplicated multiplication
performs exponentiation
Question 25
25.
The print() function can output values of :
any number of arguments (including zero)
just one argument
any number of arguments (excluding zero)
not more than five arguments