Quiz
Final Exam
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (54)
1def fun (n):
for i in range (n):
yield s
for x in fun (3) :
print (x, end-")- A2***
- B****
- C******
- D*
2What is the name of the directory/folder created by Python used to store pye files?
- A__pycfiles__
- B__cache__
- C__pycache__
- D___pyc___
3What is the expected output of the following code, located in the file module.py?
print(__name__)- A__module.py__
- B__main__
- Cmodule.py
- Dmain
4What is the expected behavior of the following snippet?
try:
raise Exception
except:
print ("c")
except BaseException:
print ("a")
except Exception:
print ("b")- AThe code will output c
- BThe code will cause an error
- CThe code will output a
- DThe code will output b
5What is the expected output of the following code?
from datetime import timedelta
delta - timedelta (weeks - 1, days - 7, hours - 11)
print (delta)- A14 days, 11:00:00
- B1 week, 7 days, 11 hours
- C7 days, 11:00:00
- D2 weeks, 11:00:00
6OWhat is the expected output of the following snippet?
class X:
pass
class Y (X) :
pass
class 2(Y):
pass
x-=X()
z=Z
print (isinstance (x, 2), isinstance (z, X))- ATrue False
- BFalse True
- CFalse False
- DTrue True
7What is the expected output of the following piece of code?
х, у, z = 3, 2, 1
z, Y, x-=x, Y, z
print (x, y. 2)- A1 2 2
- B2 1 3
- C3 2 1
- D1 2 3
8What is the expected behavior of the following code?
x="\"
print (len (x))- AThe code will cause an error
- BThe code will ouput a2
- CThe code will output 3
- DThe code will output 1
9OWhat is the expected output of the following code?
import calendar
c= calendar.calendar (calendar. UNDAY)
for weekday in c.iterweekdays (:
print (weekday, end=" ")- A6 0 1 2 3 4 5
- B$u
- CSu Mo Tu We Th Fr Sa
- D7 1 2 3 4 5 6
10Which line properly invokes the function defined as below?
def fun (a, b, c=0):
# function body- Afun(0)
- Bfun(b=0, =0)
- Cfun(1, c=2)
- Dfun(a=1, b=0, c=0)
11What is the expected output of the following piece of code?
v -1+1 // 2+1/2+ 2
print (v)- A4.0
- B3
- C3.5
- D4
12Q What is the expected result of executing the following code?
elass A:
pass
class B:
pass
elass C(A, B):
pass
print (issubelass (C, A) and issubelass (C, B))- AThe code will print True
- BThe code will print an empty line
- CThe code will print False
- DThe code will raise an exception
13What is the expected output of the following code?
my_string 1= "Bond"
my string 2 ="James Bond"
print (my_string_1.isalpha (), my_string_2.isalpha ())- ATrue True
- BTrue False
- CFalse False
- DFalse True
14What is the expected behavior of the following code snippet?
my_list = (1, 2, 3, 41
my_1ist - list (map (lambda x: 2*x, my_list))
print (my_1ist)- AThe code will cause a runtime error
- BThe code will output 2 4 6 8
- CThe code will output 1 2 3 4
- DThe code will output 10
15How many stars (*) will the following snippet send to the console?
i = 4
while i > 0 :
i -= 2
print ("*")
if i == 2:
break
else:
print ("*")- Azero
- BThe snippet will enter an infinite loop, constantly printing one * per line
- Cone
- Dtwo
16What is the expected result of executing the following code?
class A:
def _init_(self):
pass
def f(self):
return 1
def g():
return self.f0
a = A()
print (a.g())- AThe code will raise an exception
- BThe code will output 1
- CThe code will output True
- DThe code will ouput 0
17 If you want to write a byte array's content to a stream, which method can you use?
- Awrite()
- Bwritefrom()
- Cwriteto()
- Dwritebytearray()
18Knowing that the function named f() resides in the module named m, and the code contains the following import statement:
from f import m
Choose the right way to invoke the function:- Amodif()
- BThe function cannot be invoked because the import statement is invalid
- Cmod.f()
- Df()
19Select the true statements. (Select two answers)
- APyPi is short for Python Package installer
- BPyPi the only existing Python repository
- CPyPI is short for Python Package index
- DPyPI is one of many exisiting Python repositories
20What is the expected output of the following piece of code if the user enters two lines containing 1 and 2 respectively?
y = input ()
x = input ()
print (x + y)- A12
- B21
- C3
- D2
21What is the expected output of the following code?
def a (x) :
def b():
return x + x
return b
x - a('x')
y = a()
print (x () + y())- Ax
- Bxxxxxx
- Cxx
- Dxxxx
22 Which of the following functions provided by the os module are available in bothWindows and Unix? (Select two answers)
- Agetgid()
- Bgetgroups()
- Cchdir()
- Dmkdir()
23What is the expected output of the following snippet?
d = {}
d['2'] = [1, 2]
d['1'] = [3, 4]
for x in d.keys ():
print (d(x) [1], end="")- A24
- B31
- C42
- D13
24What is the expected behavior of the following code?
x = “””
“””
print (len (x))- AThe code will output 1
- BThe code will output 3
- CThe code will cause an error
- DThe code will output 2
25What can you do if you want to tell your module users that a particular variable should not be accessed directly?
- AStart its name with a capital letter
- BUse its number instead of its name
- CBuild its name with lowcase letters only
- DStart its name with _ or __
26Which operator would you use to check whether two values are equal?
- A===
- Bis
- C==
- D=
27 A package directory/folder may contain a file intended to initialize the package. What is its name?
- A__init.py__
- B__init__
- C__init__.py
- Dinit.py
28How many empty lines will the following snippet send to the console?
my_list = [[ c for c in range (r)] for r in range (3)]
for element in my_list:
if len (element) < 2:
print ()- Aone
- Bthree
- Ctwo
- Dzero
29What is the expected behavior of the following snippet?
my_string = 'abcdef’
def fun (s) :
del s[2]
return s
print (fun (my_string))- AThe program will cause an error
- BThe program will output abdef
- CThe program will output abcef
- DThe program will output acdef
30 What is the expected result of executing the following code?
class A:
def a(self):
print ('a')
class B:
def a(self) :
print ('b')
class C(A, B) :
def c(self) :
self.a()
o = C()
o.c()- AThe code will print c
- BThe code will print a
- CThe code will print b
- DThe code will raise an exception
31Which of the following sentences is true about the snippet below?
str_1 = ‘string’
str_2 = str_1[:]- AStr_1 is lonnger than str_2
- BStr_2 is longer than str_1
- CStr_1 and str_2 are different names of the same string
- DStr_1 and str_2 are different (but equal) strings
32The Exception class contains a property named args - what is it?
- AA string
- BA list
- CA tuple
- DA dictionary
33What is the expected output of the following code?
class A:
A = 1
def _init_(self) :
self.a = 0
print (hasattr (A, 'A'))- A0
- BTrue
- C1
- DFalse
34What is the expected output of the following code?
from datetime import datetime
datetime = datetime (2019, 11, 27, 11, 27, 22)
print (datetime.strftime ('%Y/%m/%d %H: %M: %S'))- A2019/nov/27 11:27:22
- B19/11/27 11:27:22
- C2019/November/27 11:27:22
- D2019/11/27 11:27:22
35What is the expected effect of running the following code?
class A:
init_(self, v) : def _
self._a = v + 1
a = A(0)
print (a._a)- AThe code will output 1
- BThe code will output 0
- CThe code will raise an AttributeError expception
- DThe code will output 2
36What is true about the following snippet?
def fun (d, k, v) :
d[k] = v
my_dictionary = ()
print (fun (my_dictionary, '1', 'v'))- AThe code will output v
- BThe code is erroneous
- CThe code will outpt 1
- DThe code will output none
37What is the expected output of the following snippet?
d = {'one': 1, 'three': 3, 'two': 2}
for k in sorted (d.values ()) :
print (k, end='')- A3 1 2
- B3 2 1
- C2 3 1
- D1 2 3
38What is the expected output of the following snippet?
t = (1, 2, 3, 4)
t = t(-2:-1)
t = t[-1]
print (t)- A(3)
- B33
- C3
- D(3,)
39What is true about the following piece of code?
print ("a", "b", "c", sep="'")- AThe code will output a b c
- BThe code will output a ‘b’ c
- CThe code is erroneous
- DThe code will output abc
40What is the expected output of the following snippet?
print (len ((i for i in range (0, -2)1))- A3
- B1
- C2
- D0
41What is PEP 8?
- AA document that describes an extension to pythons import mechanism which improves sharing of python source code files
- BA document that describe the development and realease schelude for python version
- CA document that provides coding conventions and style guide for python code
- DA document that provides coding conventions and style guide for the C code comprising C implementation of Python
42 What is the expected output of the following code?
t =(1, )
t = t(0] + t[0]
print (t)- A1
- B2
- C(1,1)
- D(1,)
43What is the expected behavior of the following piece of code?
d = (1: 0, 2: 1, 3: 2, 0: 1)
x = 0
for y in range (len (d)) :
x = d[x]
print (x)- AThe code will output 1
- BThe code will output 0
- CThe code will cause a runtime error
- DThe code will output 2
44What is the expected behavior of the following piece of code?
x =16
while x > 0:
print ('*', end='')
x //- 2- AThe code will output ******
- BThe code will output ***
- CThe code will enter an Infinite loop
- DThe code will output *
45If there is a finally: branch inside the try: block, we can say that:
- AThe finally: branch wont be executed if any of the except: branches is executed
- BThe finally: branch will be executed when there is no else: branch
- CThe finally: branch will always excecuted
- DThe filanlly: branch wont be executed if no exception is raised
46 What is the expected behavior of the following snippet?
def fun (x) :
return 1 if x + 2 != 0 else 2
print (fun (fun (1)))- AThe program will output none
- BThe program will output 2
- CThe program will output 1
- DThe code will cause a runtime error
47. What is the expected output of the following code?
class A:
A = 1
def _init_(self, v=2):
self.v - v + A.A
A.A += 1
def set (self, v) :
self.v += v
A.A += 1
return
a - A()
a.set (2)
print (a.v)- A3
- B5
- C1
- D7
48What pip operation would you use to check what Python packages have been installed so far?
- AHelp
- BDir
- CList
- DShow
49 What is true about the following line of code?
print (len ( (1, )))- AThe code is erroneous
- BThe code will output 2
- CThe code will output 0
- DThe code will output 1
50What is the expected output of the following snippet?
try:
raise Exception
except BaseException:
print ("a", end=')
else:
print ("b", end=")
finally:
print ("c")- Aac
- Bab
- Ca
- Dbc
51If the class constructor is declared as below:
class Class:
def _init_(self) :
pass- AObject = Class(1)
- BObject = Class(1,2)
- CObject = Class(None)
- DObject = Class()
52What is true about the following code snippet?
def fun (par2, parl):
return par2 + parl
print (fun (par2=1, 2))- AThe code will output 0
- BThe code will output 1
- CThe code will output 2
- DThe code is erroneous
53What value will be assigned to the x variable?
z = 2
y = 1
x = y < z or z > y and y > z or z < y- A1
- BTrue
- CFalse
- D0
54 What is the sys.stdout stream normally associated with?
- AThe screen
- BThe keyboard
- CA null device
- DThe printer
Informações
- Descrição
- Quiz sobre Final Exam, criado por _ _ em 27-01-2022.
- Autor
- _ _
- Idioma
- English
- Visualizações
- 24
- Avaliação
- Ainda sem avaliações Avalie este quiz