Test
Pyton 1
Crea una cuenta gratis para terminar este test
Guarda tu progreso y consulta tu resultado final.
¿Ya tienes cuenta? Inicia sesión
Preguntas del test (35)
1What is the output of the following piece of code if the user enters two lines
containing 3 and 2 respectively?- A3
- B0
- C2
- D1
2What value will be assigned to the x variable?
z = 0
y - 10
x - y < z and z > y or y > z and z < y- A0
- B1
- CFalse
- DTrue
3The following snippet:
def function_1 (a) :
return None
def function 2 (a) :
return function_1 (a) + function 1 (a)
print (function_2 (2) )- Awill output 2
- Bwill output 16
- Cwill output 4
- Dwill cause a runtime error
4What will be the output of the following snippet?
a=1
b=0
a=a^b
b=a^b
a=a^b
print (a, b)- A1 0
- B11
- C01
- D00
5What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup - tup[-2:-1)
tup - tup[-1]
print (tup)- A(4)
- B(4,)
- C4
- D44
6Take a look at the snippet and choose the true statement:
nums = [1, 2, 3]
vals - numa
del vals [:]- Anums is longer than vals
- Bthe snippet will cause a runtime error
- Cnums and vals have the same length
- Dvals is longer than nums
7What is the output of the following snippet?
det - {'one ': 'two', 'three': 'one', 'two': 'three')
v - del['three']
for k in range (len (det)) :
v - dct [v]
print (v)- Athree
- Bone
- Ctwo
- D('one','two','three')
8What is the output of the following snippet?
my_list - (1, 21
for v in range (2) :
my_list.insert (-1, my list [v])
print (my 1ist)- A[1, 2, 1, 2]
- B[2, 1, 1, 2]
- C[1, 1, 1, 2]
- D[1, 2, 2, 21
9What is the output of the following piece of code if the user enters two lines
containing 2 and 4 respectively?
x = float (input ())
y = float (input ())
print (y * (1/ x))- A1.0
- B2.0
- C0.0
- D4.0
10The following snippet:
def func (a, b):
relurn b
print (func (b-2, 2)- Awill output None
- Bwill output 4
- Cwill output 2
- Dis erroneous
11What is the output of the following snippet?
def fun (x, y) :
if x =- y:
return x
else:
return fun (x, y-1)
print (fun (0, 3))- A1
- B0
- C2
- Dthe snippet will cause a runtime error
12What is the expected behavior of the following program?
foo - (1, 2, 3)
foo.index (0)- AThe program will cause an AttributeError exception.
- BThe program will cause a valueError exception.
- CThe program will output 1 to the screen.
- DThe program will cause a TypeError exception.
- EThe program will cause a syntaxError exception.
13What is the output of the following code if the user enters a o ?
try:
value - input ("Enter a value: ")
print (int (value)/len (value))
except ValueError:
print ("Bad input...")
except ZeroDivisionError:
print ("Very bad input...")
except TypeError:
print ("Very very bad input...")
except:
print ("Booo!")- AVery bad input...
- B0.0
- CBooo!
14Which of the following lines correctly invoke the function defined below? (Select two
answers)
def fun (a," b, c=0):
# Body of the function.- Afun (b-0, a=0)
- Bfun ()
- Cfun (0, 1, 2)
- Dfun (b=1)
15What is the output of the following snippet?
def fun (inp-2, out-3) :
return inp * out
print (fun (out-2))- A2
- B6
- C4
- Dthe snippet is erroneous and will cause SyntaxError
16What is the output of the following snippet?
def fun (x):
if x $ 2 -- 0:
return 1
else:
return 2
print (fun (fun (2) ))- A2
- BNone
- C1
- Dthe code will cause a runtime error
17The result of the following division:
1 // 2- Acannot be predicted
- Bis equal to o
- Cis equal to 0.5
- Dis equal to 0.0
18Which of the following sentences are true about the code? (Select two answers)
nums - [1, 2, 3]
vals = nums- Avals is longer than nums
- Bnums has the same length as vals
- Cnums and vals are different names of the same list
- Dnums and vals are different lists
19What is the output of the following piece of code?
Y - 2
X, Y, z = X, X, Y
I, Y, z - x, y, z
print (x, y, 2)- A122
- B121
- C212
- D112
20Which of the following variable names are illegal and will cause the SyntaxError
exception? (Select two answers)- Aprint
- BIn
- Cfor
- Din
21Assuming that my_tuple is a correctly created tuple, the fact that tuples are
immutable means that the following instruction:
my_tuplel1] = my_tuple[1] + my_tuple [0]- Ais fully correct
- Bcan be executed if and only if the tuple contains at least two elements
- Cmay be illegal if the tuple contains strings
- Dis illegal
22How many stars (*) will the following snippet send to the console?
1 - 0
while i < i + 2 :
i += 1
print ("*")
else:
print ("*")- Aone
- Bzero
- Ctwo
- Dthe snippet will enter an infinite loop, printing one star per line
23Which of the following snippets shows the correct way of handling multiple
exceptions in a single except clause?- Aexcept (TypeError, ValueError, ZeroDivisionError)
# Some code. - Bexcept (TypeError, ValueError, ZeroDivisionError) :
# Some code. - Cexcept TypeError, ValueError, ZeroDivisionError:
# Some code.
- Aexcept (TypeError, ValueError, ZeroDivisionError)
24How many hashes () will the following snippet send to the console?
1st - [[x for x in range (3)] for y in range (3) ]
for r in range (3) :
for c in range (3) :
if 1st[r] [c]$ 2 !- 0:
print ("t")- Asix
- Bzero
- Cnine
- Dthree
25What is the output of the following piece of code?
print ("a", "b", "c", sep-"sep")- Aasepbsepe
- Babc
- Casepbsepcsep
- Dacb
26What will happen when you attempt to run the following code?
print (Hello, World!)- AThe code will print Hello, World! to the console.
- BThe code will raise the SyntaxError exception.
- CThe code will raise the TypeError exception.
- DThe code will raise the AttributeError exception.
- EThe code will raise the ValueError exception.
27What is the output of the following snippet?
dd - ("1": "0", "0": "1")
for x in dd. vals ():
print (x, end="")- Athe code is erroneous (the dict object has no vals () method)
- B0 0
- C0 1
- D1 0
28The meaning of a positional argument is determined by:
- Aits connection with existing variables
- Bits value
- Cits position within the argument list
- Dthe argument's name specified along with its value
29What is the expected behavior of the following program?
try:
print (5/0)
break
except:
print ("Sorry, something went wrong...")
except (ValueError, ZeroDivisionError):
print ("Too bad...")- AThe program will cause a valueError exception and output the followingmessage: Too bad...
- BThe program will cause a ValueError exception and output a default errormessage.
- CThe program will raise an exception handled by the first except block.
- DThe program will cause a ZeroDivisionError exception and output the
following message: Too bad... - ESyntaxError
30An operator able to check whether two values are not equal is coded as:
- Anot ==
- B<>
- C=/=
- D!=
31How many elements does the 1st list contain?
1st = (i for i in range (-1, -2)]- Atwo
- Bzer
- Cthree
- Done
32What is the output of the following snippet?
my_list = [x * x for x in range (5))
def fun (1st) :
del 1st (lat [2]]
return lst
print (fun (my_list))- A[0, 1, 4, 9]
- B[0, 1, 4, 16]
- C[1, 4, 9, 16]
- D[0, 1, 9, 16]
33What is the output of the following piece of code?
x = 1// 5 + 1 / 5
print)- A0.0
- B0.4
- C0.2
- D0
34What is the output of the following snippet?
dct - ()
dct['1'] - (1, 2)
det ['2'] - (2, 1)
for x in det.keys () :
print (det (x) [1l, end-"")- A(1,2)
- B21
- C12
- D(2,1)
35What is the output of the following piece of code if the user enters two lines
containing 3 and 6 respectively?
y - input ()
x - input 0
print (x + y)- A3
- B63
- C36
- D6
Información
- Descripción
- Test sobre Pyton 1, creado por _ _ el 21/01/2022.
- Autor
- _ _
- Idioma
- English
- Visitas
- 13
- Valoración
- Aún sin valoraciones Valora este test