Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
43 views

Java Question Bank

Java Question bank

Uploaded by

dyash2412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Java Question Bank

Java Question bank

Uploaded by

dyash2412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

1.

What do you call a command-line interpreter which lets you interact with your OS
and execute Python commands and scripts?
A. An editor
B. A console
C. A compiler
D. Jython
2. What is the expected behavior of the following program?
print("Hello!")
A. The program will output ("Hello!") to the screen
B. The program will generate an error message on the screen
C. The program will output Hello! to the screen
D. The program will output "Hello!" to the screen
3. What is the best definition of a script?
A. It’s an error message generated by the interpreter
B. It’s an error message generated by the compiler
C. It’s a text file that contains which make up a Python program
D. It’s a text file that contains sequences of zeroes and ones
4. What is the expected behavior of the following program?
print("Goodbye!")
A. The program will output Goodbye! to the screen
B. The program will generate an error message on the screen
C. The program will output("Goodbye!")
D. The program will output "Goodbye!"

5. What is machine code?


A. A high-level programming language consisting of instruction lists that humans can
read and understand
B. A medium-level programming language consisting of the assembly code designed
for the computer processor
C. A low-level programming language consisting of binary digits/bits that the
computer reads and understands
D. A low-level programming language consisting of hexadecimal digits that make up
high-level language instructions
6. Select the true statements?
A. Python is a good choice for creating and executing tests for applications
B. Python 3 is backwards compatible with Python 2
C. Python is a good choice for low-level programming e.g., when you want to
implement an effective driver
D. Python is free, open-source, and multiplatform
7. The \n digraph forces the print() function to:
A. stop its execution
B. duplicate the character next to the digragh
C. break the output line
D. output exactly two characters: \ and n
8. What is the output of the following snippet if the user enters two lines containing 2
and 4 respectively?
x = int(input())
y = int(intpu())
x=x/y
y= y/x
print(y)
A. 8.0
B. the code will cause a runtime error
C. 4.0
D. 2.0
9. What is the output of the following snippet?
z=y=x=1
print(x, y, z, sep='*')
A. 1 1 1
B. x*y*z
C. 1*1*1
D. x y z
10. What is the output of the following snippet?
x = 1 / 2 + 3 // 3 + 4 **2
print(x)
A. 8.5
B. 0
C. 17.5
D. 17
11. What is the output of the following snippet if the user enter two lines
containing 2 and 4 respectively?
x = int(input())
y = int(input())
print(x + y)
A. 2
B. 24
C. 4
D. 6
12. Which of the following variable names are illegal?
A. True
B. And
C. TRUE
D. True
13. The result of the following division:
1/1
A. is equal to 1.0
B. is equal to 1
C. cannot be evaluated
D. cannot be predicted
14. What is the output of the following snippet?
y = 2 + 3 * 5.
print(Y)
A. the snippet will cause an execution error
B. 25.
C. 17
D. 17.0
15. What is the output of the following snippet?
x=1
y=2
z=x
x=y
y=z
print (x, y)
A. 1 2
B. 1 1
C. 2 1
D. 2 2
16. The 0o prefix means that the number after it is denoted as:
A. Hexadecimal
B. Octal
C. decimal
D. Binary
17. The value twenty point twelve times ten raised to the power of eight should be written
as:
A. 20.12*10^8
B. 20E12.8
C. 20.12E8.0
D. 20.12E8
18. What is the output of the following snippet if the user enter two lines containing 2
and 4 respectively?
x = int(intput())
y = int(intput())
x = x // y
y = y //x
print(y)
A. the code will cause a runtime error
B. 2.0
C. 8.0
D. 4.0
19. What is the output of the following snippet if the user enter two lines
containing 11 and 4 respectively?
x = int(intput())
y = int(intput())
x=x%y
x=x%y
y=y%x
print(y)
A. 3
B. 2
C. 4
D. 1
20. The print() function can output values of:
A. not more than five arguments
B. any number of arguments (including zero)
C. any number of arguments (excluding zero)
D. just one argument
21. What is the output of the following snippet if the user enters two lines
containing 3 and 6 respectively?
x = input()
y = int(input())
print(x * y)
A. 333333
B. 36
C. 18
D. 666
22. Left-sided binding determines that the result of the following expression:
1 // 2 * 3 is equal to :
A. 0.0
B. 0
C. 4.5
D. 0.166666666666666666
23. Which of the following statement are true?
A. The result of the / operator is always an integer value.
B. The ** operator uses right-sided binding.
C. Adding precedes multiplication.
D. The right argument of the % operator cannot be zero.
24. What is the output of the following snippet if the user enters two lines
containing 2 and 4 respectively?
x = input()
y = input()
print(x + y)
A. 4
B. 2
C. 6
D. 24
25. The meaning of the keyword parameter is determined by:
A. its value
B. the argument’s name specified along with is value
C. its connection with exiting variables
D. its position within the argument list
26. How many stars (*) will the following snippet send to the console?

i=0

while i <= 3 :

i += 2

print("+")

a. three
b. zero
c. one
d. two
27. After execution of the following snippet, the sum of the all vals elements will equal
to:

vals = [0, 1, 2]

vals.insert(0, 1)
del vals[1]

a. 3
b. 4
c. 2
d. 5
28. How many hashes(#) will the following snippet send to the console?

for i in range(1):

print("#")

else:

print("#")

a. zero
b. three
c. two
d. one
29. How many hashes(#) will the following snippet send to the console?

var = 0

while var < 6:

var += 1

if var % 2 == 0:

continue

print("#")

a. zero
b. three
c. two
d. one
30. What is the output of the following snippet?

my_list = [3, 1, -2]

print(my_list[my_list(-1)])
a. -2
b. -1
c. 3
d. 1
31. How many stars(#) will the following snippet send to the console?

var = 0

while i <= 5:

i += 1

if vi % 2 == 0:

break

print("*")

a. three
b. two
c. one
d. zero
32. What is the output of the following snippet?

my_list = [1, 2, 3, 4]

print(my_list[-3:-2])

a. [2, 3]
b. [2, 3, 4]
c. []
d. [2]
33. How many hashes(#) will the following snippet send to the console?

var = 1

while var < 10:

print("#")

var = var << 1

a. two
b. eight
c. four
d. one
34. Take a look at the snippet, and choose the true statements: (Select two answer)

nums = [1, 2, 3]

vals = nums

del vals[1:2]

a. nums is longer than vals


b. nums and vals are of the same length
c. nums and vals refer to the same list
d. nums is replicated and assigned to vals
35. What is the output of the following snippet?

my_list = [[0, 1, 2, 3] for i in rage(2)]

print(my_list[2][0])

a. 1
b. 2
c. 0
d. the snippet will cause a runtime error
36. What value will be assigned to the x variable?

z = 10
y=0

x = y < z and z > y or y > z and z < y

a. 1
b. 0
c. True
d. False
37. Which of the following sentences are true? (Select two answers)

nums = [1, 2, 3]

vals = nums[-1:-2]

a. nums and vals are two different lists


b. vals is longer than nums
c. nums and vals are of the same length
d. numsis longer than vals
38. What is the output of the following snippet?

my_list = [1, 2, 3]

for v in range(len(my_list)):

my_list.insert(1, my_list[v])
print(my_list)

a. [1, 2, 3, 1, 2, 3]
b. [1, 2, 3, 3, 2, 1]
c. [1, 1, 1, 1, 2, 3]
d. [3, 2, 1, 1, 2, 3]
39. An operator able to check whether two values are equal is code as:

a. =
b. !=
c. ==
d. ===
40. The second assignment:

vals = [0, 1, 2]

vals[0], vlas[2] = vals[2], vals[0]

a. doesn’t change the list


b. reverses the list
c. shortens the list
d. extends the list
41. The value eventually assigned to x is equal to :

x=1

x = x == x

a. 0
b. 1
c. True
d. False
42. How many elements does the my_list list contain?

my_list = [i for i in range(-1, 2)]

a. two
b. three
c. four
d. one
43. Which of the following lines properly starts a function using two parameters, both
with zeroed default values?

a. def fun (a=b=0) :


b. def fun (a=0, b=0) :
c. fun fun (a=0, b) :
d. fun fun (a, b=0) :
44. Which of the following statement are true? (Select two answers)
a. The None value can be assigned to variables
b. The None value cannot be used outside functions
c. The None value can be used as an argument of arithmetic operators
d. The None value can be compared with variables
45. The following snippet:

def func_1(a):

return a ** a
def func_2(a):

return func_1(a) * func_1(a)

print(func_2(2))

a. will output 2
b. will output 16
c. will output 4
d. is erroneous
46. What code would you insert instead of the comment to obtain the expected output?

Expected output:

Code:

dictionary = {}

my_list = ['a', 'b', 'c', 'd']

for i in range(len(my_list) - 1):

dictionary[my_list[i]] = (my_list[i], )

for i in sorted(dictionary.key()):

k = dictionary[i]

# Insert your code here.

a. print(k["0"])
b. print(k['0'])
c. print(k)
d. print(k[0])
47. The following snippet:

def func(a, b):


return a ** a

print(func(2))

a. is erroneous
b. will output 2
c. will output 4
d. will return None
48. What is the output of thee following snippet?

def fun(inp=2, out=3):

return inp * out

print(fn(out =2))

a. 2
b. 6
c. 4
d. the snippet is erroneous
49. Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable
means that the following instruction:

my_tuple[1] = my_tuple[1] + my_tuple[0]

a. can be executed if and only if the tuple contains at least two elements
b. is illegal
c. may be illegal if the tuple contains string
d. is fully correct
50. A function defined in the following way: (Select two answers)

def function(x=0):

return x

a. may be invoked with exactly one argument


b. must be invoked with exactly one argument
c. must be invoked without any argument
d. may be invoked without any argument
51. What is the output o the following snippet?

def fun(x):

x += 1
return x

x=2

x = fun(x + 1)

print(x)

a. 3
b. 5
c. the code erroneous
d. 4
52. What is the output of the following snippet?

my_list = ['Mary', 'had', 'a', 'little', 'lamb']

def my_list(my_list):

del my_list[3]

my_list[3] = 'ram'

print(my_list(my_list))

a. [‘Mary’, ‘had’, ‘a’ ,’lamb’]


b. [‘Mary’, ‘had’, ‘a’ ,’ram’]
c. [‘Mary’, ‘had’, ‘a’ ,’little’, ‘lamb’]
d. no output, the snippet is erroneous
53. What is the output of the following snippet?

def f(x):

if x == 0:

return 0

return x + f(x - 1)

print(f(3))

a. 6
b. the code is erroneous
c. 1
d. 3
54. What is the output of the following snippet?

tup = (1, 2, 4, 8)

tup = tup[1:-1]

tup = tup[0]

print(tup)

a. the snippet is erroneous


b. (12)
c. (2, )
d. 2
55. What is the output of the following snippet?

def fun(x):

global y

y=x*x

return y

fun(2)

print(y)

a. the code will cause a runtime error


b. 4
c. None
d. 2
56. What is the output of the following snippet?

dictionary = {'one': 'two', 'three': 'one', 'two': 'three'}

v = dictionary['one']

for k in range(len(dictionary)):

v = dictionary[v]
print(v)

a. three
b. one
c. (‘one’, ‘two’, ‘three’)
d. two
57. Select the true statements about the try-exception block in relation to the following
example. (Select two answers.)

try:

# Some code is here...

except:

# some code is here...

a. if you suspect that a snippet may raise an exception, you should place it in
the try block
b. The code that follows the try statement will be executed if the code in
the except clause runs into an error.
c. The code that follows the except statement will be executed if the code in
the try clause runs into an error.
d. If there is a syntax error in code located in the try block, the except branch
will not handle it, and a SyntaxError exception will be raised instead.
58. Which one if the following lines properly starts a parameterless function definition?

a. def fun:
b. def fun():
c. function fun():
d. fun function():
59. What is the output of the following snippet?

def fun(x, y, x):

return x + 2 * y + 3 * z

print(fun(0, z=1, y=3))

a. 9
b. 0
c. 3
d. the snippet is erroneous
60. What is the output of the following code?

try:
value = input("Enter a value: ")

print(value/value)

except:

print("Bad input...")

except ZeroDivisionError:

print("Very bad input...")

except TypeError:

print("Very very bad input...")

except:

print("Booo!")

a. Booo!
b. Bad input...
c. Very very bad input...
d. Very bad input...
61. What is the output of the following snippet?

def ant():

print(var + 1, end ='')

var = 1

any()

print(var)

a. 12
b. 22
c. 11
d. 21
62. The fact that tuples belong to sequence types means that:
a. they can be indexed and sliced like lists
b. they can be extended using the .append() method
c. they can be modified using the del instruction
d. they are actually lists
63. What is the output of the following snippet?

tup = (1, 2, 4, 8)

tup = tup[-2:-1]

tup = tup[-1]

print(tup)

a. 44
b. 4
c. (4)
d. (4,)
64. Assuming that my_tuple is a correctly crated tuple, the fact that tuples are immutable
means that the following instruction:

my_tuple[1] = my_tuple[1] + my_tuple[0]

a. may be illegal if the tuple contains strings


b. is illegal
c. can be executed if and only if the tuple contains at least two elements
d. is full correct
65. Which of the following lines correctly. invoke the function defined below?
(Select two answers)

def fun(a, b, c=0):

#Body of the function.

a. fun()
b. fun(0, 1, 2)
c. fun(b=0, a=0)
d. fun(b=1)
66. The following snippet:

def func(a, b):

reeturn b ** a

print(func(b=2, 2))

a. will output 4
b. will output None
c. will output 2
d. is erroneous
67. The following snippet:

def function_1(a):

return None

def function_2(a):

return function_1(a) * functin_1(a)

print(function_2(2))

a. will output 16
b. will crate a runtime error
c. will output 4
d. will output 2
68. What is the output of the following snippet?

def fun(x):

if c % 2 == 0:
return 1

else:

return 2

print(fun(fun(2)))

a. 2None
b. 1
c. the code will cause a runtime error
d. 2
69. What is the output of the following piece of code?

print("a", "b", "c", sep="sep")

a. a b c
b. abc
c. asepbsepcsep
d. asepbsepc
70. Which of the following sentences are true about the code? (Select two answers)

nums = [1, 2, 3]

vals = nums

a. nums and vals are different names of the same list


b. vals is longer tha nums
c. nums and vals are different lists
d. nums has the same length as vals
71. What is the output of the following snippet?

my_list = [1, 2]

for v in range(2):

my_list.insert(-1, my_list[v])

print(my_list)

a. [1, 2, 2, 2]
b. [1, 2, 1, 2]
c. [2, 1, 1, 2]
d. [1, 1, 1, 2]
72. What is the output of the following piece of code?

x = 1 // 5 + 1 / 5

print(x)

a. 0.0
b. 0
c. 0.4
d. 0.2
73. What is the output of the following piece of code?

x=1

y=2

x, y z = x, x, y

z, y, z = x, y, z

print(x, y, z)

a. 2 1 2
b. 1 2 2
c. 1 1 2
d. 1 2 1
74. What is the output of the following snippet?

def fun(inp =2, out =3):

return inp * out

print(fun(out =2))

a. 4
b. 6
c. 2
d. the snippet is erroneous and will cause SyntaxError
75. How many element does the lst list contain?

lst = [i for i in range(-1, -2)]

a. two
b. three
c. zero
d. one
76. What is the output of the following code if the user enters a 0 ?

try:
value = input("Enter a value: ")

print(int(value) / len(value))

except ValueError:

print("Bad input...")

except ZeroDivisionError:

print("Very bad input...")

except TypeErrorq:

print("Very very bad input...")


except:

print("Booo!")

a. Very bad input...


b. Very very bad input...
c. Bad input...
d. Booo!
e. 0.0
f. 1.0
77. What is the output of the following snippet?

dct = {'one': 'two', 'three': 'one', 'two': 'three'}

v = dct['three']

for k in range(len(dct)):

v = dct[v]

print(v)

a. two
b. ('one', 'two', 'three')
c. three
d. one
78. What value will be assignment to the x variable?

z=0

y=0

x = y < z and z > y or y > z and z < y

a. False
b. 0
c. 1
d. True
79. Which of the following variable names are illegal and will cause the SystemError
exception? (Select two answers)
a. print
b. in
c. for
d. in
80. What 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...")

a. The program will cause a ValueError exception and output the following message Too
bad...
b. The program will cause a SyntaxError exception
c. The program will cause a ValueError exception and output a default error message.
d. The program will raise an exception handle by the first except block.
e. The program will cause a ZeroDivisionError exception and output the following
message: Too bad...
f. The program will cause a ZeroDivisionError exception and output a default error
message.
81. Take a look at the snippet and choose the true statement:

nums = [1, 2, 3]

vals = nums

del vals[:]
a. the snippet will cause a runtime error
b. vals is longer than nums
c. nums is longer than vals
d. nums and vals have the same length
82. What is the output of the following snippet?

my_list = [x * x for x in range (5)]

def fun(lst):

del lst[lst[2]]

return lst

print(fun(my_list))

a. [0 , 1, 4, 9]
b. [0, 1, 4, 16]
c. [0, 1, 9, 16]
d. [1, 4, 9, 16]
83. What is the output of the following snippet? dd

= {"1": "0", "0": "1"}

for x in dd.vals():

print(x, end="")

a. 0 1
b. 1 0
c. 0 0
d. the code is erroneous(the dict object has no vals() method)
84. What is the output of the following piece of code if the user enters two lines
containing 3 and 2 respectively?

x = int(input())

y = int(input())

x=x%y

y=y%x

print(y)
a. 1
b. 3
c. 2
d. 0
85. Which if the following snippets shows the correct way of handing multiple exceptingin a
single except clause?
a. except TypeError, ValueError, ZeroDivisinError:
# Some code.
b. except: (TypeError, ValueError, ZeroDivisinError)
# Some code.
c. except TypeError, ValueError, ZeroDivisinError
# Some code.
d. except: TypeError, ValueError, ZeroDivisinError
# Some code.
e. except: (TypeError, ValueError, ZeroDivisinError):
# Some code.
f. except (TypeError, ValueError, ZeroDivisinError)
# Some code.
86. What will be the output of the following snippet?a =

b=0

a=a^b

b=a^b

a=a^b

print (a, b)

a. 1 1
b. 0 0
c. 1 0
d. 0 1
87. How many stars (*) will the following snippet send to the console? i

=0

while i < i + 2 :
i += 1

print("*")

else:

print("*")

a. zero
b. the snippet will enter an infinite loop, printing one star per line
c. one
d. two
88. How many hashes (*) will the following snippet sent to the console? lst

= [[x for x in range(3)] for y in range(3)]

for r in range(3):

for c in rang(3):

if lst[r][c] % 2 != 0:

print("#")

a. nine
b. zero
c. three
d. six
89. Knowing that a function named fun() resides in a module named mod , choosethe
correct way to import it:
a. from mod import fun
b. import fun from mod
c. from fun import mod
d. import fun
90. What is the expected output of the following code? from
random import randint
for i in range(2):
print (randint(1,2), end='')
a. 12, or 21
b. there are millions of possible combinations, and the exact output cannot be
predicted
c. 12
d. 11, 12, 21, or 22
91. During the first import of a module, Python deploys the pyc files in the
directory called:
a. mymodules
b. init
c. hashbang
d. pycache
92. What is the expected value of the result variable after the following code is
executed?

import math

result = math.e != math.pow(2, 4)

print(int(result))

a. 0
b. 1
c. False
d. True
93. The following statement

from a.b import c


causes the import of:

a. entity a from module b from package c


b. entity c from module a from package b
c. entity b from module a from package c
d. entity c from module b from package a

118. What is true about the pip search command? (Select three answers)
a. all its searches are limited to locally installed packages
b. it needs working internet connection to work
c. it searches through all PyPI packages
d. it searches through package names only
119. When a module is imported, its contents:
a. are executed once (implicitly)
b. are ignored
c. are executed as many times as they are imported
d. may be executed (explicitly)
120. Choose the true statements. (Select two answers)
a. The version function from the platform module returns a string with your
Python version
b. The processor function from the platform module returns an integer with the
number of processes currently running in your OS
c. The version function from the platform module returns a string with your OS
version
d. The system function from the platform module returns a string with your OS
name
121. What is true about the pip install command? (Select two answers)
a. it allows the user to install a specific version of the package
b. it installs a package system-wide only when the --system option is specified
c. it installs a package per user only when the --user option is specified
d. it always installs the newest package version and it cannot be changed
122. Knowing that a function named fun() resides in a module named mod , and it
has been imported using the following line:

import mod
Choose the way it can be invoked in your code:

a. mod->fun()
b. mod::fun()
c. mod.fun()
d. fun()
123. The digraph written as #! is used to:
a. tell a Unix or Unix-like OS how to execute the contents of a Python file
b. tell an MS Windows OS how to execute the contents of a Python file
c. create a docstring
d. make a particular module entity a private one
124. A function which returns a list of all entities available in a module is called:

a. entities()
b. content()
c. dir()
d. listmodule()
125. The following code:

print(ord('c') - ord('a'))

prints:

a. 0
b. 2
c. 3
d. 1
126. The following code:

print (float("1, 3" ))


a. prints 1, 3
b. raises a ValueError exception
c. prints 1.3
d. prints 13
127. The top-most Python exception is called:

a. TopException
b. Exception
c. BaseException
d. PythonException
128. The following statement:

assert var == 0
a. is erroneous
b. will stop the program when var != 0
c. has no effect
d. will stop the program when var == 0
129. UNICODE is a standard:

a. used by coders from universities


b. honored by the whole universe
c. like ASCII, but much more expansive
d. for coding floating-point numbers
130. ASCII is:
a. a predefined Python variable name
b. a standard Python module name
c. a character name
d. short for American Standard Code for Information Interchange
131. The following code:

print(3 * 'abc' +'xyz')


prints:

a. xyzxyzxyzxyz
b. abcabcxyzxyz
c. abcabcabcxyz
d. abcxyzxyzxyz
132. UTF-8 is:

a. a Python version name


b. the 9th version of the UTF standard
c. a form of encoding Unicode code points
d. a synonym for byte
133. Entering the try: block implies that:
a. all of the instructions from this block will be executed
b. some of the instructions from this block may not be executed
c. the block will be omitted
d. none of the instructions from this block will be executed
134. The unnamed except: block:
a. must be the first one
b. can be placed anywhere
c. cannot be used if any named block has been used
d. must be the last one
135. The following code:

print('Mike' > " Mikey")


prints:

a. 0
b. 1
c. True
d. False
136. The following code:

print(chr(ord('z') - 2))
prints:

a. z
b. y
c. a
d. x
137. The following code:

x = '\' '
print(len(x))
prints:

a.
3
b.
2
c.
20
d.
1
138. Which of the following are examples of Python built-in concrete
exceptions?(Select two answers)

a. ArithemticError
b. IndexError
c. BaseException
d. ImportError
139. What will be the result of executing the following code?

class Ex(Exception):

def_init_(self,msg):

Exception._init_(self,msg + msg)
self.args = (msg,)

try:

raise Ex('ex')

except Ex as e:

print(e)

except Exception as e:

print(e)

a. it will print ex
b. it will print exex
c. it will print an empty line
d. it will raise an unhandled exception
140. A data structure described as LIFO is actually a:
a. list
b. stack
c. heap
d. tree
141. What will be the output of the following code?

class A:

A=1

print(hasattr(A, 'A'))

a. 0
b. False
c. 1
d. True
142. What will be the effect of running the following code?

class A:
def_init_(self,v):

self._a = v + 1

a = A(0)

print(a._a)

a. 2
b. The code will raise an AttributeError exception
c. 0
d. 1
143. What will be the result of executing the following code?

class A:

pass

class B(A):

pass

class C(B):

pass

print(issubclass(C,A))

a. it will print 1
b. it will print False
c. it will print True
d. it will raise an exception
144. What will be the result of executing the following code?
class A:

def_str_(self):

return 'a'

class B:

def_str_(self):

return 'b'

class C(A, B):

pass

o = C()

print(o)

a. it will print b
b. it will print c
c. it will print a
d. it will raise an exception
145. What will be the result of executing the following code?

class A:

def a(self):

print('a')

class B:
def a(self):

self.a()

o = C()

o.c()

a. it will raise an exception


b. it will print a
c. it will print c
d. it will print b
146. What will be the result of executing the following code?

try:

raise Exception(1,2,3)

except Exception as e:

print (len(e.args))

a. it will print 1
b. it will print 2
c. it will raise as unhandled exception
d. it will print 3
147. What will be the output of the following code?

class A:

X=0

def init (self,v = 0):

self.Y = v

A.X += v
a = A()

b = A(1)

c = A(2)

print(c.X)

a.2
b.3
c.0
d.1
148. If the class’s constructor is declared as below, which one of the assignments
is valid?

class Class:

def init (self):

pass

a. object = Class
b. object = Class()
c. object = Class(self)
d. object = Class(object)
149. What will be the result of executing the following code?

def f(x):

try:

x=x/x

except:

print("a",end='')

else:

print("b",end='')

finally:
print("c",end='')

f(1)

f(0)

a.
it will raise an unhandled exception
b.
it will print bcac
c.
it will print acac
d.
it will print bcbc
150. If there is a superclass named A and a subclass named B, which one of the
presented invocations should you put instead of the comment?

class A:

def init (self):

self.a = 1

class B(A):

def init (self):

# put selected line here.

self.b = 2

a. A. init (self)
b. init ()
c. A. init ()
d. A. init (1)
151. What will be the result of executing the following code?

class A:

def init (self):

pass

a = A(1)

print(hasattr(a,'A'))
a. 1
b. False
c. it will raise an exception
d. True
152. What will be the result of executing the following code?

class A:

def init (self):

return 'a'

class B(A):

def init (self):

return 'b'

class c(B):

pass

o = C()

print(o)

a. it will print c
b. it will print b
c. it will print a
d. it will raise an exception
153. What will be the output of the following code?

class A:

def init (self,v = 1):

self.v =v

def set(self,v):

self.v = v
return v

a = A()

print(a.set(a.v + 1))

a. 2
b. 1
c. 3
d. 0
154. What will be the result of executing the following code?

class A:

v=2

class B(A):

v=1

class C(B):

pass

o =C()

print(o.v)

a. it will raise an exception


b. it will print 2
c. it will print an empty line
d. it will print 1
155. What is the expected result of executing the code?

def I():

s = 'abcdef'
for c in s[::2]:

yield c

for x in I():

print(x, end=' ')

a. It will print abcdef


b. It will print an empty line
c. It will print bdf
d. It will print ace
156. What keyword would you us to define an anonymous function?

a. afun
b. lambda
c. def
d. yield
157. Select the true statements. (Select two answers)
a. The lambda function can accept a maximum of two arguments
b. The lambda function can evaluate multiple expressions
c. The lambda function can evaluate only one expressrion
d. The lambda function can accept any number of arguments
158. Look at the code below:

my_list = [1, 2, 3]

# insert line of code here.

print(foo)

Which snippet would you insert in order for the program to output the following result
(tuple):

1, 4, 27
a. foo = list(map(lambda x: x**x, my_list))
b. foo = tuple(map(lambda x: x*x, my_list))
c. foo = list(map(lambda x: x*x, my_list))
d. foo = tuple(map(lambda x: x**x, my_list))
159. What is the expected output of the following code?

from datetime import date


date_1 = date(1992, 1, 16)

date_2 = date(1992, 2, 5)

print(date_1 - date_2)

a. 345
b. 345 days
c. 345, 0:00:00
d. 345 days, 0:00:00
160. Which program will produce the following output:

Mo Tu We Th Fr Sa Su

a. import calendar

b. print(calendar.weekheader(3))

c. import calendar
d. print(calendar.weekheader(2))

e. import calendar

f. print(calendar.week)

g. import calendar

h. print(calendar.weekheader())

161. What is the expected result of executed the following code?

def o(p):

def q():

return'*' *p

return q

r = o(1)

s = o(2)
print(r9) + s())

a. it will print ***


b. it will print ***
c. it will print **
d. it will print *
162. Look at the code below:

my_tuple = (0, 1, 2. 3, 4, 5, 6)

# Insert line of code here.

print(foo)

Which snippet would you insert in order for he program to output the following result
(list):

[2, 3, 4, 5, 6]

a. foo = list(filter(lambda x: x-0 and x-1, my_tuple))

b. foo - list(filter(lambda x: x==0 and x==1, my_tuple))

c. foo = tuple(filter(lambda x: x>1, my_tuple))

d. foo = tuple(filter(lambda x: x-0 and x-1, my_tuple))

163. What is the expected result of executed the following code?

def fun(n):

s = '+'

for i in range(n):

s += s

yield s

for x in fun(2):

print(x, end='')
a. It will print+++
b. It will print ++
c. It will print ++++++
d. It will print +
164. What is the meaning of the value represented by errno.EEXITS ?
a. File doesn’t exist
b. Bad file number
c. Permission denied
d. File exists
165. What is the expected result of the following code?

b = bytearray(3)

print(b)

a. 3
b. bytearray(b'\x00\x00\x00')
c. bytearray(0, 0, 0)
d. bytearray(b'3')
166. What is the expected output of the following code?

from datetime import datetime

datetime = datetime(2019, 11, 27, 11, 27, 22)

perint(datetime.strftime('%y/%B/%d %H:%M:%s'))

a. 19/November/27 11:27:22
b. 2019/Nov/27 11:27:22
c. 2019/11/27 11:27:22
d. 19/11/27 11:27:22
167. What is the expected output of the following code?

import os

os.mkdir('pictures')

os.chdir('pictures')

os.mkdir('thumbnails')

os.chdir('thumbnails')

os.mkdir('tmp')
os.chdir('../')

print(os.getcwd())

a. The orint to the thumbnails directory


b. The path to the pitcures directory
c. The path to the tmp directory
d. The path to th root directory
168. What is the expected output of the following code?

import os

os.mkdir('thumbnails')

os.chdir('thumbnails')

sizes = ['small', 'medium', 'large']

for size in sizes:

os.mkdir(size)

print(os.listdir())

a. ['.', '..', 'large', 'small', 'medium']


b. []
c. ['.', 'large', 'small', 'medium']
d. ['large', 'small', 'medium']
169. What is the expected result of the following code?

import calendar

c = calendar.Calendar()

for weekday in c.iterweekdays():

print(weekday, end="")

a. 1234567
b. Su Mo Tu We Th Fr Sa
c. 01234567
d. Mo Tu We Th Fr Sa Su
170. The following code:
x = "\\\\"

print(len(x))

a.will print 1
b.will print 2
c.will cause an error
d.will print 3
171. What information can be read using the uname function provided by
the os module? (Select two answers)

import os

os.mkdir('pictures')

os.chdir('pictures')

print(os.getcwd())

a. Last login date.


b. Current path
c. Operating system name
d. Hardware identifier
172. The following statement:

assert var != 0

a. ia erroneous
b. has no effect
c. will stop the program when var == 0
d. will stop the program whrn var !=0
173. What is he except output of the following code?

class A:

A=1

def init (self):

self.a = 0

print(hasattr(A, 'a'))

a. 0
b. True
c. 1
d. False
174. What is the excepted result of the following code?

from datetime import timedelta

delta = timedelta(weeks = 1, days = 7, hours = 11)

print(delta * 2)

a. 28 days, 22:00:00
b. 2 weeks, 14 days, 22 hours
c. 7 days, 22:00:00
d. The code will raise an exception
175. What is the excepted output of the following code?

class A:

def init (self, v=2)

def set(self, v=1):

self.v +=v

return self.v

a = A()

b=a

b.set()

print(a.v)

a. 1
b. 0
c. 2
d. 3
176. What is the expected effect of running the following code?

class A:
def init (self, v):

self. a = v + 1

a = A(0)

print(a. a)

a. The code will raise an AttributeError except


b. The code will print 2
c. The code will print 0
d. The code will print 1
177. Knowing that a function named fun() resides in a module named mod , and
was imported using the following statement:
from mod import fun
choose the right to invoke the fun() function:

a. mod:fun()
b. mod::fun()
c. fun()
d. mod.fun()
178. What output will appear after running the following snippet?

a. The number of all the entities residing in the math module


b. A string containing the fully qualified name of the module
c. An error message
d. A list of all the entities residing in the math module
179. Look at the code below:

import random

# Insert lines of code here.

print(a, b,

Which lines of code would you insert so that it is possible for the program to output the
following result:

6 82 0

a. a = random.randint(0, 100)
b. b = random.randrange(10, 100, 3)
c. c = random.choice((0, 100, 3))

d. a = random.choice((0, 100, 3))

e. b = random.randrange(10, 100, 3)

f. c = random.randint(0, 100)

g. a = random.randrange(10, 100, 3)

h. b = random.randint(0, 100)

i. c = random.choice((0, 100, 3))

j. a = random.randint(0, 100)

k. b = random.choice((0, 100, 3))

l. c = random.randrange(10, 100, 3)

180. What is the expected result of the following code?

from datetime import datetime

datetime_1 = datetime(2019, 11, 27, 11, 27, 22)

datetime_2 = datetime(2019, 11, 27, 0, 0, 0)

print(datetime_1 - datetime_2)

a. o days
b. 0 days, 11:27:22
c. 11:27:22
d. 11 hours, 27 minutes, 22 seconds
181. What is the expected result of the following code?

import calendar

calendar.setfirstweekday(calendar.SUNDAY)

print(calendar.weekheader(3))
a. Su Mo Tu We Th We Fr Sa
b. Sun Mon Tue Wed Thu Fri Sat
c. Tu
d. Tue
182. what is the expected result of executing the following code?

class A:

a. The code will print c


b. The code will raise an excepion
c. The code will print b
d. The code will print a
183. Look at the following code:

numbers [0, 2, 7, 9, 10]

# Insert line of code here.

print(list(foo))

Which line would you insert in order for the program to produce the expected output?

[0, 4, 49, 81, 100]

a. foo = lambda num: num ** 2, numbers


b. foo = lambda num: num * 2, numbers)
c. foo = filter(lambda num: num ** 2, numbers)
d. foo = map(lambda num : num ** 2, numbers)
184. What is the expected result of executing the following code?

class I:

def init (self):

self.s = 'abc'

self.i = 0

def init (self):

return self

def next (self):


if self.i == len(self.s):

raise StopIteration

v = self.s[self.i]

self.i +=1

return v

for x in I():

print(x, end='')

a.
The code will print 210
b.
The code will print abc
c.
The code will print 012
d.
The code will print cba
185. The complied Python bytecode is stored in files which have their names
ending with:

a. py
b. pyb
c. pc
d. pyc
186. Which pip command would you use to uninstall a previously install package?
a. pip delete packagename
b. pip –uninstall packagename
c. pip –remove packagename
d. pip uninstall packagename
187. What is the excepted result of executed the following code?

try:

raise Exception(1, 2, 3)

except Exception as e:

print(len(e.args))

a. The code will raise an unhandled exception


b. The code will print 2
c. The code will print 3
d. The code will print 1
188. What is the excepted result of executed the following snippet?

try:

raise Exception

except BaseException:

print("a")

except Exception:

print("b")

except:

print("c")

a. b
b. a
c. An error message
d. 1
189. What is the expected result of executing the following code?

class A:

pass

class B(A):

pass

class C(B):

pass

print(issubclass(A, C))

a. The code will print Ture


b. The code will print 1
c. The code will print False
d. The code will raise an exception
190. If you want to fill a byte array with data read in from a stream, which method
you can use?

a. The read() method


b. The readbytes() method
c. The readfrom() method
d. The readinto() method
191. The following code:

print(float("1.3"))

a. will print 1.3


b. will print 13
c. will print 1,3
d. will raise a ValueError exception
192. The following code:

print(chr(ord('p) + 2))

will print:

a. q
b. s
c. r
d. t
193. If there are more than one except: branch after the try: clause, we can say that:
a. exactly one except: block will be executed
b. one or more except: blocks will be executed
c. not more than one except: block will be executed
d. none of the except: blocks will be executed
194. If the class constructor is declared in the following way:

class Class:

def init (self, vla = 0):

pass

which one of the assignments is invalid?


a. object = Class(1)
b. object = Class(None)
c. object = Class(1, 2)
d. object = Class()
195. What is the expected result of the following snippet?

try:
raise Exception

except:

print("c")

except BaseException:

print("a")

except Exception:

print("b")

a. The code will cause a syntax error


b. 1
c. b
d. a
196. What is the expected result of the following code?

def my_fun(n):

s = '+'

for i in range(n):

s += s

yield s

for x in my_fun(2):

print(x, end='')

a. The code will print +


b. The code will print +++
c. The code will print ++
d. The code will print ++++++
197. Look at the following code:

numbers = [i*i for i in range(5)]


# Insert line of code here.

print(foo)

Which line would you insert in order for the program to produce the expected output?

[1, 9]

a. foo = list(filter(lambda x: x % 2, numbers))


b. foo = list(filter(lambda x: x / 2, numbers))
c. foo = list(map(lambda x: x % 2, numbers))
d. foo = list(map(lambda x: x // 2, numbers))
198. What is the expected result of executing the following code?

def o(p):

def q():

return '*' * p

return q

r = o(1)

s = o(2)

print(r() + s())

a. The code will print ***


b. The code will print ****
c. The code will print *
d. The code will print **
199. The following statement:

from a.b import c

causes the import of:

a. entity a from module b from package c


b. entity b from module a from package c
c. entity c from module a from package b
d. entity c from module b from package a
200. The sys.stderr stream is normally associaated with:
a. the keyboard
b. the printer
c. a null device
d. the screen
201. What will be the output of the following code, located in the p.py file?

print( name )

a. main
b. p.py
c. main
d. p.py
202. Assuming that the open() invocation has gone successfully, the following
snippet:

for x in open('file', 'rt'))

print(x)

will:

a. read the file character by character


b. read the file line by line
c. read the whole file at once
d. cause an exception
203. If a is a stream opened in read mod, the following line:

q = s.read(1)

will read:

a. one line from the stream


b. one kilobyte from the stream
c. one buffer from the stream
d. one character from the stream
204. The following line of code:

for line in open('text.txt', 'rt'):

a. in invalid because open returns nothing


b. is invalid because open returns a non-iterable object
c. is invalid because open returns an iterable object
d. may be valid if line is a list
205. What is the expected result of the following code?

import os
os.mkdir('pictures')

os.chdir('pictures')

print(os.getcwd())

a. The code will print the owner of the created directory


b. The code will print the content of the created directory
c. The code will print the name of the created directory
d. The code will print the path to the created directory
206. Assuming that the following three files a.py ,and c.py reside in the same
directory, what will be the output produce after running the c.py file?

# file a.py

print("a", end='')

# file b.py

import a

print("b", end='')

# file c.py

print("c", end='')

import a

import b

a. cab
b. cab
c. abc
d. bac
207. What is the expected result of executing the followinf code?

class A:

def init (self):

pass
a = A(1)

print(hasattr(a, 'A'))

a. The code will print 1


b. The code will raise an exception
c. The code will print False
d. The code will print True
208. The following code:

x = " \\"

print(len(x))

a.will print 1
b.will print 3
c.will print 2
d.will cause an error
209. Which of the following commands would you use to check pip ‘s version?
(Select two answers)
a. pip version
b. pip --version
c. pip–version
d. pip3 --version
210. What is the expected output of the following snippet?

a = True

b = False

a = a or b

b = a and b

a = a or b

print(a, b)

a. False False
b. True False
c. False True
d. True False
211. What is the expected output of the following snippet?

print(len([i for i in range(0, -2)]))


a. 3
b. 1
c. 2
d. 0
212. How many stars * will the following snippet send to the console?

i=4

while i > 0 :

i -= 2

print("*")

if i == 2:

break

else:

print("*")

a. two
b. one
c. zero
d. The snippet will enter an infinite loop, constantly printing one * per line
213. What is the sys.stdout stream normally associated with?
a. The printer
b. The keyboard
c. A null device
d. The screen
214. What is the excepted output of the following snippet?

class X:

pass

class Y(X):

pass

class Z(Y):
pass

x = X()

z = Z()

print(isinstance(x, z), isinstance(z, X))

a. True True
b. True False
c. False True
d. False False
215. What is the excepted output of the following snippet?

class A:

def init (self,name):

self.name = name

a = A("class")

print(a)

a. class
b. name
c. A number
d. A string ending with a long hexadecimal number
216. What is the excepted result of executing the following code?

class A:

pass

class B:

pass

class C(A, B):

pass
print(issubclass(C, A) and issubclass(C, B))

a. The code will print True


b. The code will raise an exception
c. The code will print an empty line
d. The code will print False
217. What is the excepted output of the following code?

from datetime import datetime

datetime = datatime(2019, 11, 27, 11, 27, 22)]

print(datetime.strftime('%Y/%m/%d %H:%M:%S'))

a. 19/11/27 11:27:22
b. 2019/Nov/27 11:27:22
c. 2019/11/27 11:27:22
d. 2019/November/27 11:27:22
218. What is the excepted output of the following code?

my_string_1 = 'Bond'

my_string_2 = 'James Bond'

print(my_string_1.isalpha(), my_string_2.isalpha())

a. False True
b. True True
c. False False
d. True False
219. The meaning of a Keyword argument is determined by its:
a. both name and value assigned to it
b. position within the argument list
c. connection with existing variables
d. value only
220. Knowing that the function named m, and the code contains the
following import statement:
from f import m
Choose the right way to invoke the function:

a. mod.f()
b. The function cannot be invoked because the import statement is invalid
c. f()
d. mod:f()
221. The Exception class contains a property named args -what is it?
a. A dictionary
b. A list
c. A string
d. A tuple
222. Which is the expected behavior of the following snippet?

def fun(x):

return 1 if x % 2 != else 2

print(fun(fun(1)))

a.The program will output None


b.The code will cause a runtime error
c.The program will output 2
d.The program will output 1
223. What can you do if you want tell your module users that a particular variable
should not be accessed directly?

a. Start its name with or


b. Start its name with a capital letter
c. Use its number instead of its name
d. Build its name with lowercase letters only
224. What is the expected output of the following snippet?

d = ('one': 1, 'three': 3, 'two':2)

for k in sorted(d.values()):

print(k, end=' ')

a. 123
b. 312
c. 321
d. 231
225. Select the true statements.(Select two answers)
a. The first parameter of a class method dose not have to be named self
b. The first parameter of a class method must be named self
c. If a class contains the init method, it can return a value
d. If a class contains the init method, it cannot return any value
226. Select the true statements. (Select two answers)
a. PyPI is short for Python Package Index
b. PyPI is the only existing Python repository
c. PyPI is one of many existing Python repository
d. PyPI is short for Python Package Installer
227. What is the expected output of the following snippet?

t = (1, 2, 3, 4)

t = t[-2:-1]

t = t[-1]

print(t)

a.
(3)
b.
(3,)
3b.
c.
33
228. Which of the following functions provide by the os module are available in
both Windows and Unix? (Select two answers)
a. chdir()
b. getgid()
c. getgroups()
d. mkdir()
229. What is the expected output of the following piece of code?

v = 1 + 1 // 2 + 1 / 2 + 2

a. 4.0
b. 3
c. 3.5
d. 4
230. If s is a stream opened in read mode, the following line:

q = s.readlines()

will assign q as :
a. dictionary
b. tuple
c. list
d. string
231. Which of the following sentences is true about the snippet below?

str_1 = 'string'

str_2 = str_1[:]

a. str_1 is longer than str_2


b. str_1 and str_2 are different (but equal) strings
c. str_1 and str_2 are different names of the same string
d. str_2 is longer than str_1
232. What is the expected result of executed the following code?

class A:

def init (self):

pass
def f(self):

return 1

def g():

return self.f()

a = A()

print(a.g())

a.The code will output True


b.The code will output 0
c.The code will output 1
d.The code will raise an exception
233. What is the expected output of the following code, located in the
file module.py ?

print( name )

a. main
b. modle.py
c. main
d. module.py
234. What is the excepted output of the following code?

def a(x):

def b():

return x + x

return b

x = a('x)

y = a('')

print(x() + y())

a. xx
b. xxxx
c. xxxxxx
d. x
235. What is the excepted behavior of the following piece of code?

x = 16

while x > 0:

print('*', end='')

x //= 2

a.
The code will output *****
b.
The code will output ***
c.
The code will output *
d.
The code will error an infinite loop
236. A package directory/folder may contain a file intended to initialize the
package. What is its name?

a. init.py
b. init.py
c. init .
d. init .py
237. If there is a finally: branch inside the try: block, we can say that:
a. the finally: branch will always be executed
b. the finally: branch won’t be executed if any of the except: branch is executed
c. the finally: branch won’t be executed if no exception is raised
d. the finally: branch will be executed when there is no else: branch
238. What value will be assigned to the x variable?

z=2

y=1

x = y < z or z > y and y > z or z < y

a. True
b. False
c. 0
d. 1
239. If you want to write a byte array’s content to a stream, which method can you
use?

a. writeto()
b. writefrom()
c. write()
d. writebytearray()
240. What is the expected behavior of the following snippet?

try:

raise Exception

except:

print("c")

except BaseException:

print("a")

except Exception:

print("b")

a. The code will cause an error


b. The code will output b
c. The code will output c
d. The code will output a
241. What is true about the following code snippet?

def fun(par2, par1):

return par2 + par1

print(fun(par2 = 1, 2))

a. The code is erroneous


b. The code will output 3
c. The code will output 2
d. The code will output 1
242. What is the expected output of the following piece of code?

x, y, z = 3, 2, 1

z, y, x = x, y, z

print(x, y, z)
a. 213
b. 122
c. 321
d. 123
243. What 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="")

a. 24
b. 31
c. 13
d. 42
244. What is the expected output of the following snippet?

try:

raise Exception

except BaseException:

print("a", end='')

else:

print("b", end='')

finnaly:

print("c")

a. bc
b. a
c. ab
d. ac
245. If the class constructor is declare as below:
class Class:

def init (self):

pass

which one of the assignment is valid?


a. object = Class()
b. object = Class(1,2)
c. object = Class(None)
d. object = Class(1)
246. What 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)

a. 2
b. 21
c. 12
d. 3
247. What is the expected behavior of the following snippet?

my_string = 'abcdef'

def fun(s):

del s[2]
return s

print(fun(my_string))

a. The program will cause an error


b. The program will output abdef
c. The program will output acdef
d. The program will output abcef
248. What is true about the following snippet?

def fun(d, k, v):

d[k] = v

my_dictionary = {}

print(fun(my_dictionary, '1', 'v'))

a. The code is erroneous


b. The code will output None
c. The code will output v
d. The code will output 1
249. What is the expected output of the following code?

class A:

A=1

def init (self):

self.a = 0

print(hasattr(A, 'A'))

a. False
b. 1
c. 0
d. True
250. What is the expected behavior of the following code?

x = """

"""
print(len(x))

a. The code will output 2


b. The code will output 3
c. The code will cause an error
d. The code will output 1
251. What is the expected output of the following code?

import calendar

c = calendar.Calendar(calendar.SUNDAY)

for weekday in c.iterweekdays():

print(weekday, end=" ")

a. 7123456
b. 6012345
c. Su Mo Tu We Th Fr Sa
d. Su
252. What is the expected output of the following code?

def fun(n):

s=''

for i in range(n):

s += '*'

yield s

for x in fun(3):

print(x, end='')

a. ****
b. ******
c. 2***
d. *
253. What is the expected output of the following code?

t = (1, )
t = t[0] + t[0]

print(t)

a. 2
b. (1, )
c. (1, 1)
d. 1
254. 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()

a. The code will print c


b. The code will print a
c. The code will raise an exception
d. The code will print b
255. What is the expected behavior of the following code snippet?

my_list = [1, 2, 3, 4]

my_list = list(map(lambda x: 2*x, my_list))


print(my_list)

a. The code will cause a runtime error


b. The code will output 1 2 3 4
c. the code will output 10
d. The code will output 2 4 6 8
256. What 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)

a.
The code will output 0
b.
The code will output 1
c.
The code will cause a runtime error
d.
The code will output 2
257. What pip operation would you use to check what Python package have been
installed so far?
a. show
b. list
c. help
d. dir
258. What is true about the following line of code?

print(len((1, )))

a. The code will output 0


b. The code is erroneous
c. The code will output 1
d. The code will output 2
259. Which line properly invokes the function defined as below?

def fun(a, b, c=0):

# function body

a. fun(b=0, b=0)
b. fun(a=1, b=0, c=0)
c. fun(1, c=2)
d. fun(0)
260. What is the expected behavior of the following code?

import os

os.makedirs('pictures/thumbnails')

os.rmdir('pictures')

a. The code will delete both the pictures and thumbnails directories
b. The code will delete the pictures directory only
c. The code will raise an error
d. the code will delete the thumbnails directory only
261. What is true about the following piece of code?

print("a", "b", "c", sep=" ' ")

a. The code is erroneous


b. The code will output abc
c. The code will output a'b'c
d. The code will output a b c
262. What is the expected behavior of the following code?

x = "\"

print(len(x))

a. The code will output 3


b. The code will cause an error
c. The code will output a2
d. The code will output 1
263. 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)

a. 7
b. 1
c. 3
d. 5
264. How 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()

a. two
b. three
c. zero
d. one
265. The following fragment of code is written using a for loop. Re-write it using a
while
for i in range(1, 16) :
if i % 3 == 0 :
print (i)

Ans: i = 1
while i < 16:
if i % 3 == 0 :
print (i)
i += 1

266. Rewrite the following code fragment using for loop:


while num > 0 :
count += 1
sum += num
num –= 2
if count == 10 :
print (sum/float(count))
break

Ans: for i in range(num, 0, -2):


count += 1
sum += i
if count == 10 :
print (sum/float(count))
break

267. Rewrite following code fragment using while loops :


min = 0
max = num
if num < 0 :
min = num
max = 0 # compute sum of integers
# from min to max

for i in range(min, max + 1):


sum += i
Ans: min = 0
max = num
if num < 0 :
min = num
max = 0 # compute sum of integers
# from min to max
i = min
while i <= max:
sum += i
i += 1

268. Rewrite the following code fragment using for loop:


while num > 0 :
count += 1
sum += num
num –= 2
if count == 10 :
print (sum/float(count))
break
ans: for i in range(num, 0, -2):
count += 1
sum += i
if count == 10 :
print (sum/float(count))
break

You might also like