NEW
Font size
WorksheetsPython PCAP 31-03
Total questions: 50
Worksheet time: 25mins
What is the output of the following code if spam.py is run?
Syntax Error
spam eggs ham
spam ham
eggs ham spam
spam ham eggs
How do you call the function ham() saved as spam.py below?
import spam; ham()
import spam; spam.ham()
Import spam; spam.ham()
Import spam; ham()
import spam.ham; ham()
How will you shorten the function call to spam() defined inside
packageA.subpackageB.subpackageC.moduleD?
import packageA.subpackageB.subpackageC.moduleD
import packageA.subpackageB.subpackageC.moduleD alias p
from packageA.subpackageB.subpackageC.moduleD import spam alias s
from packageA.subpackageB.subpackageC.moduleD import spam
from packageA,subpackageB.subpackageC,moduleD import *
What is the output of the following code?
-1.1
-2
-1
-1.0
-2.0
What is the output of the following code?
0
0.5
1
1.0
TypeError: type int doesn't define __sqrt__ method
Select all option(s) which returns a random number between 0 and 100?
random.random(100)
random.random(0, 100)
random.random()*100
random.random(100.0)
random.random(0. 100)
What is the datatype of the return value of the function platform.version()?
float
int
char
str
array
Which of the statements below is valid?
Python is interpreted however it compiles the py file into pyc file
Python is interpreted therefore it never compiles the py files
Compiled Python files is not stored inside the __pycache__ folder
Compiled Python files is stored inside the __cache__ folder
Compiled Python files is stored inside the __pyc__ folder
The extension of a compiled bytecode of the Python source file is
.pyc
.py
.pc
.__pycache__
__pycache__
Select valid option(s) about __init__.py
__init__.py is not automatically executed when the regular package is
imported
__init__.py is contained in namespace packages
__init__.py is contained in regular packages
__init__.py is automatically executed when the namespace package is
imported
__init__.py is not contained in regular packages
What directories are searched by the interpreter for spam.py given the code
below, EXCEPT?
Directory where spam.py was run
List of directories contained in PATH environment variable
Current directory if the interpreter is run interactively
List of directories in sys.path
List of directories contained in PYTHONPATH environment variable
What is the output of the following code?
No output
abcdefgh
SyntaxError: invalid syntax
NameError: name 'UndefinedException' is not defined
Add () on Line 2 and 3 to fix the syntax error
What is the output of the following code?
SyntaxError: invalid syntax
ZeroDivisionError: division by zero
No Output
NameError: name 'ZeroDivisionError' is not defined
0
Which option will print ELSE given the following code?
raise Exception
raise TypeError
raise ZeroDivisionError
replace <<< INSERT CODE HERE >>> with blank
pass
What is the output of the following code?
1345
1235
1245
145
135
What is the output of the following code?
Unhandled Exception
Surprise
Stop
Goodbye
None
What is the output of the following code?
Spam
Spam Eggs
Spam Ham
Spam Ham Eggs
Syntax Error
What is the output of the following code?
Spam
Spam Ham
Spam Spam
Ham Ham
Spam Ham Spam Ham
Which option are valid replacements for the marker in the given code?
except MathError:
except ArithmeticException:
except ZeroDivisionError:
except DivisionZeroError:
except TypeError:
What is the output of the following code?
print("\\\\")
Syntax Error
\
\\
\\\
\\\\
What is the output of the following code?
Syntax Error
TypeError: ord() takes exactly two arguments (1 given)
97 a
TypeError: chr() takes exactly two arguments (1 given)
TypeError: an integer is required (got type str)
Which option will return True given the following code, EXCEPT?
spam.startswith(ham)
spam.equals(ham)
spam.endswith(ham)
spam == ham
id(spam) == id(ham)
What is the output of the following code if the user enters 1 on the first
prompt and 2 on the second prompt?
TypeError: input() takes 0 positional arguments but 1 was given
a+b
3
12
TypeError: unsupported operand type(s) for +: 'str' and 'str'
What is the output of the following code?
SyntaxError: invalid syntax
(3, hamhamham)
(3, 0)
TypeError: unsupported operand type(s) for *=: 'str' and 'int'
(9,hamhamhamhamhamhamhamhamham)
What is the output of the following code?
SyntaxError: invalid syntax
TypeError: unsupported operand type(s) for *: 'int' and 'str'
'Yes!!!Yes!!!'
0
8
What is the output of the following code?
Hello World
spam
eggs
No output
SyntaxError: invalid syntax
What is the output of the following code?
eggs spam ham
spam ham eggs
eggs eggs eggs
eggs ham eggs
spam eggs ham
What is the output of the following code?
TypeError: __init__() missing 1 required positional argument: 'v'
3 3
3 4
3 5
3
What is the output of the following code?
0 2
1 2
2 2
Invalid Syntax
AttributeError: 'Spam' object has no attribute 'v1'
What is the output of the following code?
Hello
World
Hello World
SyntaxError: invalid syntax
No output
What is the output of the following code?
100 101
Error in Line 3
Error in Line 4
Error in Line 5
Error in Line 6
What is the output of the following code?
TypeError: Cannot create a consistent method resolution
B.spam B.spam
B.spam A.spam
A.spam A.spam
A.spam B.spam
What is the output of the following code?
No output
Super Spam
Super Ham
Super Spam Super Ham
Super Ham Super Spam
What is the output of the following code?
SyntaxError: invalid syntax
[[0], [1]]
[[1], [2]]
[[0], [0, 1]]
[[1], [1, 2]]
What is the output of the following code?
[0, 2, 4, 6, 8]
[2, 4, 6, 8, 10]
[1, 3, 5, 7, 9]
[0, 1, 3, 4, 5, 6, 7, 8, 9]
SyntaxError: invalid syntax
What is the output of the following code?
[]
[False]
[0,1,2]
[False, False, False]
SyntaxError: invalid syntax
What is the output of the following code?
None
0
[0]
[]
SyntaxError: invalid syntax
Which option will produce a non-empty list?
lst = [i for i in range(1, 5)]
lst = [i for i in range(5, 1)]
lst = [l for i in range(-5, -1)]
lst = [i for i in range(0, -5)]
lst = [i for i in range(-1, -5)]
What is the output of the following code?
[8, 9]
[9, 8]
[0, 1, 2, 3, 4, 5, 6, 7]
[7, 6, 5, 4, 3, 2, 1, 0]
[2, 3, 4, 5, 6, 7, 8, 9]
What is the output of the following code?
[0, 1, 1]
[1, 1]
[0, 1]
[0, 1, 2]
ZeroDivisionError: integer division or modulo by zero
What is the output of the following code?
[0, 2, 4, 6, 8]
[1, 2, 3, 4, 5]
[1, 2, 4, 8, 16]
[2, 4, 6, 8, 10]
SyntaxError: invalid syntax
How many stars will the following code print?
0
1
2
3
4
What is the output of the following code?
0
2
10
20
SyntaxError: invalid syntax
What is the output of the following code?
10
20
True
TypeError: tuple indices must be integers or slices
Invalid Syntax
What is the output of the following code?
[0, 1, 2]
[1, 2, 3]
[0, 2, 4]
[[0,0], [1,2], [2,4]]
SyntaxError: invalid syntax
Which option(s) are valid results of the following code if spam.txt does not
exist?
No output
2
ENOENT
No such file or directory
Error Line 6
What is the output of the following code?
10
20
True
False
Invalid Syntax
What is the output of the following code?
SyntaxError: invalid syntax
TypeError: unsupported operand type(s) for *: 'list' and 'int'
['spamspam', 'hamham']
['spam', 'ham', 'spam', 'ham']
None
What is the output of the following code?
4.0
5.0
6.0
7.0
8.0
What is the output of the following code?
SyntaxError: invalid syntax
True
False
1
0
