Quiz de Python.

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

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

a += 1
a = a + 1 if a else 1
a++
a = a + 1
Publicidade

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

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

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]

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

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 fourth element of the second list with the third element of the third list of the dl list.
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.

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

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

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 = [ ...tup ]
a, b, c, d = ('v1', 'v2', 'v3', 'v4')
tup = ('v1', 'v2', 'v3', 'v4'); a, b, c, d = [i for i in tup]
a, b, c = ['v1', 'v2', 'v3']

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 input, decoding stdout and stderr with utf-8 encoding; Waits the command to be executed and prints the stdout 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 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 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 different from zero.
Publicidade

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)

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)

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

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]

list, map, lambda, zip
zip, list, filter, lambda
list, zip, lambda, map
map, filter, lambda, list
map, zip, filter, lambda
Publicidade
ComentáriosÚltima atualização: -
Clique aqui e seja o primeiro a comentar!

Você vai gostar também

Carregando...