Quiz de Python.

Quiz de Python.

Vamos ver se você é ninja em linguagem Python? Acesse o teste e descubra.

Imagem de perfil user: Henrique Santos
1

Qual é o melhor atalho para incrementar a variável "a=0" em Python?

a = a + 1 if a else 1
a++
a = a + 1
a += 1
2

Corrija o código. def counter(): num = 0 def incrementer(): # Fill in the missing line here num += 1 return num return incrementer

nonlocal num :::: because num is in a global scope.
nonlocal num :::: because num is in an outer scope.
local num ::: because num is in a local scope.
global num ::: because num is in a local scope.
global num ::: because num is in a global scope.
3

Com base no código abaixo, qual expressão causará um TypeError? import array ar = array.array('i', [1, 2, 3, 4]) li = [1, 2, 3, 4]

ar.append('a') :::: because arrays can contain values corresponding to the same data types.
ar.append('b') ::: because the "ar" array accepts only 4 elements.
li.append(5) :::: because the "li" list accepts only 4 elements.
NDA
li.append('a') :::: because lists can contain values corresponding to different data types.
4

Qual é o valor da variável sm? dl = [[1, 2, 5, 4], [1, 2, 3, 4], [5, 2, 3, 4], [5, 4, 3, 4]] sm = dl[1][3] + dl[2][2]

7 :::: because the sum is of the second element of the fourth list with the third element of the third list of the dl list.
7 :::: because the sum is of the first element of the third list with the second element of the second list of the dl list.
7 :::: because the sum is of the third element of the first list with the second element of the second list of the dl list.
7 :::: because the sum is of the fourth element of the second list with the third element of the third list of the dl list.
5

Com base na string "s" quais expressões irão reproduzir o resultado '6-5/02' ? s = '7897+=_ABCktrJP(20/5-6) FN4'

s.split(' ')[0][16:22]
s[7::].split(' ')[0][9:15]
s.split(' ')[1][::-1]
s[::-1].split(' ')[1][1:7]
6

Você tem uma tupla de N elementos que gostaria de descompactar em uma coleção de N variáveis. Selecione uma expressão correta.

tup = ('v1', 'v2', 'v3', 'v4'); a, b, c, d = [i for i in tup]
a, b, c = ['v1', 'v2', 'v3']
tup = ('v1', 'v2', 'v3', 'v4'); a, b, c, d = [ ...tup ]
a, b, c, d = ('v1', 'v2', 'v3', 'v4')
7

O que este código faz? import subprocess v = subprocess.Popen( ['ls', '-l', '/tmp'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, encoding='utf-8' ) v.wait() if not v.returncode: stdout = v.stdout.readlines() for line in stdout: print(line, end='')

Runs an external command and collect its output, decoding stdout and stderr with utf-8 encoding; Waits the command to be executed and prints the stdout if v.returncode is zero.
Runs an external command and collect its output, decoding stdout and stderr with utf-8 encoding; Waits the command to be executed and prints the stdout if v.returncode is different from zero.
Opens a file redirecting its output into a variable named "stdout", decoding it with utf-8 encoding; Grants access to it to permit adding new lines; Waits the file to be loaded and prints its content if v.returncode is zero.
Opens a file redirecting its output into a variable named "stdout", decoding it with utf-8 encoding; Grants access to it to permit adding new lines; Waits the file to be loaded and prints its content if v.returncode is different from zero.
Runs an external command and collect its input, decoding stdout and stderr with utf-8 encoding; Waits the command to be executed and prints the stdout if v.returncode is zero.
8

Selecione todas as opções que podem preencher as linhas que faltam e corrija o código. import functools def bs(func): # Fill in the missing line here def wrapper(*args, **kwargs): r = ' + '.join([str(i) for i in args]) print(r, '=', end=' ') # Fill in the missing line here return wrapper # Fill in the missing line here def do_sum(n1, n2): result = n1 + n2 print(result) if __name__ == '__main__': do_sum(9, 7)

return func(*args, **kwargs); @bs; @functools.wraps(func)
return bs(func); @bs; @functools.wraps(func)
@bs(func); @bs; @functools.wraps(func)
9

Corrija o código. def decrement(n): while n > 0: # Fill in the missing line here n -= 1 if __name__ == '__main__': dec = decrement(8) result = [i for i in dec] print(result)

yield n :::: because this is a generator.
yield n :::: because this is a decorator.
n -= 1 :::: because we can run into an infinite loop.
return n :::: because this is a decorator.
break :::: because this is a loop.
10

Corrija o código. Quais instruções Python devem ser usadas aqui? Altere a palavra BLANK com a declaração correta, respectivamente. a = [1, 2, 3, 4, 5] b = [6, 7, 8, 9, 10] r = BLANK(BLANK(BLANK x : sum(x) if sum(x) > 7 else -1, BLANK(a, b))) output r = [-1, 9, 11, 13, 15]

map, filter, lambda, list
zip, list, filter, lambda
list, zip, lambda, map
list, map, lambda, zip
map, zip, filter, lambda
Quizur Logo

Siga nossas redes sociais:

Incorporar

Para incorporar este quiz ao seu site copie e cole o código abaixo.