Practice Test Python
star
star
star
star
star
Last updated over 1 year ago
25 questions
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)
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)
1
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
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
1
What is the expected behavior of the following program?
foo = (1, 2, 3)foo.index(1)
What is the expected behavior of the following program?
foo = (1, 2, 3)
foo.index(1)
1
What will be the output of the following snippet?
a = 0b = 1c = 0
a = a ^ cb = b ^ ac = c ^ b
print(a, b, c)
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
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))
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
An operator able to check whether two values are not equal is:
An operator able to check whether two values are not equal is:
1
What is the output of the following piece of code?
x = 1 % 5 * 1 / 5
print(x)
What is the output of the following piece of code?
x = 1 % 5 * 1 / 5
print(x)
1
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))
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))
1
Take a look at the snippet and choose the true statement:
nums = [1, 2, 3 ]vals = numsdel vals []
Take a look at the snippet and choose the true statement:
nums = [1, 2, 3 ]
vals = nums
del vals []
1
The result of the following division:
1 // 2
The result of the following division:
1 // 2
1
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 % yx = x % yy = y % x
print(y)
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)
1
What is the output of the following snippet?
dd = {"1": "0", "0": "1"}for x in dd: print(x, end=" ")
What is the output of the following snippet?
dd = {"1": "0", "0": "1"}
for x in dd:
print(x, end=" ")
1
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...")
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...")
1
Which of the following sentences are true about the code?( Select two answers)
nums = [1, 2, 3]vals = numsvals = [2, 3, 4]
Which of the following sentences are true about the code?( Select two answers)
nums = [1, 2, 3]
vals = nums
vals = [2, 3, 4]
1
The following snippet:
def func(b, a): return b ** a
print(func(b=2, 2))
The following snippet:
def func(b, a):
return b ** a
print(func(b=2, 2))
1
The value eventually assigned to x is equal to:
x =1x = x == x
The value eventually assigned to x is equal to:
x =1
x = x == x
1
Take a look at the snippet, and choose the true statements:(Select two answers)
nums = [1, 2, 3 ]vals = numsdel vals[1:2]
Take a look at the snippet, and choose the true statements:(Select two answers)
nums = [1, 2, 3 ]
vals = nums
del vals[1:2]
1
What is the output of the following snippet?
my_list = [3, 1, -2]print(my_list[-3])
What is the output of the following snippet?
my_list = [3, 1, -2]
print(my_list[-3])
1
How many stars (*) with the following snippet send to the console?
i = 0
while i <= 5: i += 2 if i % 2 == 0: break print("*")
How many stars (*) with the following snippet send to the console?
i = 0
while i <= 5:
i += 2
if i % 2 == 0:
break
print("*")
1
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]
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]
1
Which of the following statements are true?(Select two answers)
Which of the following statements are true?(Select two answers)
1
The result of the following division:
1/1
The result of the following division:
1/1
1
Which of the following variable names are illegal? (Select two answers)
Which of the following variable names are illegal? (Select two answers)
1
The ** operator:
The ** operator:
1
The print() function can output values of :
The print() function can output values of :