Pcap01 06
Pcap01 06
Pcap01 06
1. What will be the value of the i variable when the while e loop finishes its execution?
A. 1
B. 0
C. 2
D. the variable becomes unavailable
A. —
B. ++
C. <<
D. >>
3. What will the value of the i variable be when the following loop finishes its execution?
A. 10
B. the variable becomes unavailable
C. 11
D. 9
is:
A. equal to 1
B. invalid
C. equal to 2
D. equal to -1
5. A compiler is a program designed to (Choose two.)
A. three
B. one
C. two
D. Four
9. Which of the following literals reflect the value given as 34.23? (Choose two.)
A. .3423e2
B. 3423e-2
C. .3423e-2
D. 3423e2
A. 3
B. 1
C. 2
D. the code is erroneous
11. Assuming that the following snippet has been successfully executed, which of the equations are True? (Choose
two.)
12. Assuming that the following snippet has been successfully executed, which of the equations are False? (Choose
two.)
15. Assuming that String is six or more letters long, the following slice
A. 1
B. 4
C. 2
D. 3
A. abc
B. The code will cause a runtime exception
C. ABC
D. 123
18. How many elements will the list2 list contain after execution of the following snippet?
A. zero
B. five
C. seven
D. Three
19. What would you used instead of XXX if you want to check whether a certain ‘key’ exists in a dictionary called dict?
(Choose two.)
A. ‘key’ in dict
B. dict [‘key’] != None
C. dict.exists (‘key’)
D. ‘key’ in dict.keys ( )
20. You need data which can act as a simple telephone directory. You can obtain it with the following clauses (Choose
two.) (assume that no other items have been created before)
A. dir={‘Mom’: 5551234567, ‘Dad’: 5557654321}
B. dir= {‘Mom’: ‘5551234567’, ‘Dad’: ‘5557654321’}
C. dir= {Mom: 5551234567, Dad: 5557654321}
D. dir= {Mom: ‘5551234567’, Dad: ‘5557654321’}
PCAP 02.
A. fun (b=1)
B. fun (a=0)
C. fun (b=1, 0)
D. fun (1)
3. A file name like this one below says that: (Choose three.)
services, cpython 36.pyc
It will:
A. cause a runtime exception
B. print 1
C. print 0, [1]
D. print [1]
5. What can you do if you don’t like a long package path like this one?
A. you can make an alias for the name using the alias keyword
B. nothing, you need to come to terms with it
C. you can shorten it to alpha . zeta and Python will find the proper connection
D. you can make an alias for the name using the as keyword
6. What is the expected output of the following code?
A. abcef
B. The program will cause a runtime exception/error
C. acdef
D. abdef
A. 21
B. 2
C. 3
D. 12
A. print 4321
B. print <generator object f at (some hex digits)>
C. cause a runtime exception
D. print 1234
10. If you need a function that does nothing, what would you use instead of XXX? (Choose two.)
A. pass
B. return
C. exit
D. None
13. The simplest possible class definition in Python can be expressed as:
A. class X:
B. class X:
pass
C. class X:
return
D. class X: { }
14. If you want to access an exception object’s components and store them in an object called e, you have to use the
following form of exception statement:
A. except Exception (e) :
B. except e= Exception :
C. except Exception as e:
D. such an action is not possible in Python
17. You are going to read just one character from a stream called s. Which statement would you use?
A. ch = read (s, 1)
B. ch= s.input (1)
C. ch= input (s, 1)
D. ch= s.read (1)
18. What can you deduce from the following statement? (Choose two.)
19. The following class hierarchy is given. What is the expected out of the code?
A. BB
B. CC
C. AA
D. BC
20. Python’s built in function named open () tries to open a file and returns:
A. an integer value identifying an opened file
B. an error code (0 means success)
C. a stream object
D. always None
PCAP03.
1. Which of the following words can be used as a variable name? (Choose two.)
A. for
B. True
C. true
D. For
5. Which line can be used instead of the comment to cause the snippet to produce the following expected output?
(Choose two.)
Expected output:
123
Code:
A. c,b,a = b,a,c
B. c,b,a = a,c,b
C. a,b,c = c,a,b
D. a,b,c = a,b,c
6. Assuming that the V variable holds an integer value to 2, which of the following operators should be used instead of
OPER to make the expression equal to 1?
V OPER 1
A. <<<
B. >>>
C. >>
D. <<
8. UNICODE is:
A. the name of an operating system
B. a standard for encoding and handling texts
C. the name of a programming language
D. the name of a text processor
A. *- **-**-**-*
B. *-**-**-**-**-**-**-**-*
C. *-*
D. *-**-*
10. Which of the listed actions can be applied to the following tuple? (Choose two.)
tup = ()
A. tup [:]
B. tup.append (0)
C. tup [0]
D. del tup
11. Executing the following snippet will cause the dct:
A. to hold two keys named ‘pi’ linked to 3.14 and 3.1415 respectively
B. to hold two key named ‘pi’ linked to 3.14 and 3.1415
C. to hold one key named ‘pi’ linked to 3.1415
D. to hold two keys named ‘pi’ linked to 3.1415
12. How many elements will the list1 list contain after execution of the following snippet?
A. two
B. zero
C. one
D. Three
Code:
A. s.split ()
B. split (s, ‘ ‘)
C. s.split (‘ ‘)
D. split (s)
15. Assuming that 1st is a four-element list is there any difference between these two statements?
A. yes, there is, the first line empties the list, the second line deletes the list as a whole
B. yes, there is, the first line deletes the list as a whole, the second line just empties the list
C. no, there is no difference
D. yes, there is, the first line deletes the list as a whole, the second line removes all the elements except the first one
16. What should you put instead of XXX to print out the module name?
A. main
B. _main_
C. __main__
D. ___main___
19. What can you deduce from the line below? (Choose two.)
20. A two-parameter lambda function raising its first parameter to the power of the second parameter should be
declared as:
A. lambda (x, y) = x ** y
B. lambda (x, y): x ** y
C. def lambda (x, y): return x ** y
D. lambda x, y: x ** y
PCAP 04.
A. 21
B. 12
C. 3
D. none
2. A method for passing the arguments used by the following snippet is called:
A. sequential
B. named
C. positional
D. keyword
It will
A. print 2 1
B. print 1 2
C. cause a runtime exception
D. print <generator object f at (some hex digits)>
A. 2
B. The code will cause a runtime exception
C. 1
D. 3
5. What is the expected output of the following code?
A. print 0
B. cause a runtime exception
C. prints 3
D. print an empty line
6. If any of a class’s components has a name that starts with two underscores (___), then:
A. the class component’s name will be mangled
B. the class component has to be an instance variable
C. the class component has to be a class variable
D. the class component has to be a method
7. If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:
A. except Ex1 Ex2:
B. except (ex1, Ex2):
C. except Ex1, Ex2:
D. except Ex1+Ex2:
10. The following class definition is given. We want the show () method to invoke the get () method, and then output
the value the get () method returns. Which of the invocations should be used instead of XXX?
A. print (get(self))
B. print (self.get())
C. print (get())
D. print (self.get (val))
11. If S is a stream open for reading, what do you expect from the following invocation?
A. one line of the file will be read and stored in the string called C
B. the whole file content will be read and stored in the string called C
C. one character will be read and stored in the string called C
D. one disk sector (512 bytes) will be read and stored in the string called C
12. You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose
two.)
A. data = bytearray (16)
bf.readinto (data)
B. data = binfile.read (bytearray (16))
C. bf. readinto (data = bytearray (16))
D. data = bytearray (binfile.read (16))
(x,Z)
A. True False
B. True True
C. False False
D. False True
14. Assuming that the code below has been executed successfully, which of the following expressions will always
evaluate to True? (Choose two.)
A. v1 >= 1
B. v1 == v2
C. len(random.sample([1,2,3],2)) > 2
D. random.choice([1,2,3]) >=1
15. Which one of the platform module functions should be used to determine the underlying platform name?
A. platform.python_version() returns the Python version as string ‘major.minor.patchlevel’
B. platform.processor() returns the (real) processor name, e.g. ‘amdk6’.
C. platform.platform() returns a single string identifying the underlying platform with as much useful information as possible.
D. platform.uname() returns a tuple of strings (system, node, release, version, machine, processor) identifying the underlying platform.
A. False
B. None
C. True
D. 0
17. With regards to the directory structure below, select the proper forms of the directives in order to import module_a.
(Choose two.)
18. A Python module named pymod.py contains a function named pyfun(). Which of the following snippets will let you
invoke the function? (Choose two.)
A. import pymod
pymod.pyfun()
B. from pymod import pyfun
pyfun()
C. from pymod import *
pymod.pyfun()
D. import pyfun from pymod
pyfun()
19. What is true about Python packages? (Choose two.)
A. a package is a single file whose name ends with the pa extension
B. a package is a group of related modules
C. the __name__ variable always contains the name of a package
D. the pyc extension is used to mark semi-compiled Python packages
A. it outputs 3
B. the code is erroneous and it will not execute
C. it outputs 1
D. it outputs 2
2. Which of the following snippets will execute without raising any unhandled exceptions? (Choose two.)
A.
B.
t
C.
D.
A. it outputs error
B. it outputs <class ‘IndexError’>
C. it outputs list assignment index out of range
D. the code is erroneous and it will not execute
class E(Exception):
def __init__(self, message):
Self.message = message
def__str__(self):
Return “it’s nice to see you”
try:
print (“I feel fine”)
raise Exception (“What a pity”)
except E as e:
Print (e)
else:
Print(‘the show must go on”)
A. it raises an exception
B. it outputs 0
C. it outputs 3
D. it outputs ‘None’
A. it raises an exception
B. it outputs True
C. it outputs False
D. it outputs nothing
12. Assuming that the snippet below has been executed successfully, which of the following expressions evaluate to
True? (Choose two.)
string = ‘python’[::2]
string = string[-1] + string[-2]
A. it outputs 0
B. it outputs 1 tambah (:) ini jawapannya
C. it raises an exception
D. it outputs 2
14. Assuming that the following inheritance set is in force, which of the following classes are declared properly?
(Choose two.)
16. Assuming that the code below has been placed inside a file named code.py and executed successfully, which of
the following expressions evaluate to True? (Choose two.)
A. len(ClassB.__bases__) == 2 False
B. ClassA.__module__ == ‘__main__’ True
C. __name__ == ‘code.py’ False
D. str(Object) == ‘Object’ False
A. it outputs 1
B. it outputs 3
C. it outputs 6
D. it raises an exception
PCAP 06
1. Assuming that the following piece of code has been executed successfully, which of the expressions evaluate to
True? (Choose two.)
2. Assuming that the code below has been executed successfully, which of the expressions evaluate to True?
(Choose two.)
A. len(Class.__dict__) == 1 False
B. ‘data’ in Class.__dict__ True
C. ‘var’ in Class.__dict__ False ‘Var’ in Class.__dict__ True
D. ‘data’ in Object.__dict__ False
4. Which of the following lines of code will work flawlessly when put independently inside the add_new() method in
order to make the snippet’s output equal to [0, 1, 2]? (Choose two.)
A. self.queue.append(self.get_last() + 1)
B. self.queue.append(get_last() + 1)
C. self.queue.append(self.queue[-1] + 1)
D. queue.append(self.get_last() + 1)
A. a
B. c
C. an exception is raised
D. b
6. What is the expected output of the following code if there is no file named non_existing_file inside the working
directory?
A. 124
B. 1234
C. 24
D. 13
7. What is the expected output of the following code if the file named existing_text_file is a non-zero length text file
located inside the working directory?
A. the length of the first line from the file
B. -1
C. the number of lines contained inside the file
D. the length of the last line from the file
A. it outputs [1, 3]
B. the code is erroneous and it will not execute
C. it outputs [3, 1]
D. it outputs [4, 2, 0]
9. Assuming that the following code has been executed successfully, which of the expressions evaluate to True?
(Choose two.)
A. b() == 4
B. a != b
C. a is not None
D. a() == 4
A. 3
B. 5
C. 4
D. an exception is raised
11. Which of the following lambda definitions are correct? (Choose two.)
A. lambda x,y: (x,y)
B. lambda x,y: return x//y – x%y
C. lambda x,y: x//y – x%y
D. lambda x,y = x//y – x%y