Font size
WorksheetsBroken Python(Practice Test)
Total questions: 63
Worksheet time: 32mins
Which code should you use to import a function named abc from a Python module named xyz?
import abc
from xyz import abc
import abc from xyz
import mod xyz fn abc
When using Python, which mathematic operation returns a value of 2?
42 / 4
42 / / 4
42 % 4
42 ** . 4
When using Python, what is the result of the mathematic operation 1 ** (2 * 3) / 4 + 5?
0.11
0.67
5.25
6.50
Which function from the math module can you use to round up the number 12.34 to 13?
math.cell()
math.float()
math.floor()
math.trunc()
Which function returns only whole, even numbers from within the range from 1 to 100?
random.choice(1, 100, even)
random.randint (1, 100, 2)
random.randrange(2, 101, 2)
random.uniform(1, 100)
True or False: A datetime.timedelta object stores only days, seconds, and microseconds.
True
False
Which two statements about the pydoc module are true?
It generates documentation from the docstrings in a module.
It generates documentation for a module without importing it.
It imports a module and then generates documentation for the module.
It automatically suppresses module functions from running while generating documentation for the module.
Which of the following are valid expressions for the datetime.timedelta objects t1, t2, and t3? (Choose all that apply.)
t1 = t2 – t3
t1 = 6 % t2
month = datetime.timedelta(1 month)
year = datetime.timedelta(365 days)
Which command should you use to generate HTML documentation for a Python module named py?
pydoc program
pydoc -h program.py
pydoc -t program.py
pydoc -w program
Which command should you use to generate text documentation for a Python module named py?
pydoc program
pydoc -h program.py
pydoc -t program.py
pydoc -w program
Which expression defines an object named hiredate with a value of July 1, 2018?
hiredate = datetime.date(year = 2018, month = 7, day = 1)
hiredate = datetime.datetime(year = 2018, month = 7, day = 1)
hiredate = datetime.timedate(year = 2018, month = 7, day = 1)
hiredate = datetime.timedelta(days = 43282)
Which element should come first in a multi-line docstring for a function?
A blank line
The function arguments
The function parameters
A summary line that describes the function as a command
Which is an example of a valid one-line docstring?
# Return the path of the current working directory
// Return the path of the current working directory //
docstring("Return the path of the current working directory.")
"""Return the path of the current working directory."""
Which information should you include in a multi-line docstring for a function?
arguments, return values, and exceptions
function name
function parameters
public methods and instance variables
True or False: A global variable is available from any Python module.
True
False
You are comparing two numerical values in the following operation:
In [1]: 9 ___ 9
Out[1]: True
Which operator correctly completes the operation?
=>
=!
>=
Which statement about local variables is true?
A local variable can be read from the global scope.
You can use the same variable name in multiple functions.
A local variable in one function can be read from another function.
A function can update a global variable in a local scope by using the same name for a local variable and assigning a new value.
You perform the following Boolean comparison operation:
(x >= 10) not (x < 20) and (x % 2 == 0)
For which two numbers is the comparison operation True? (Choose two.)
10
20
25
50
Complete the sentence to be true for code running in a Python environment.
A local scope is created...
when a function is created
when a function is called
when a function returns to its caller
when a function is destroyed
When a function calls a subfunction, which variables are maintained in memory? (Choose all that apply.)
The global variables
The function variables
The subfunction variables
You are performing the following operation:
In [1]: 10 == 20
Out[1]: _____
What is the result of the operation?
#Hit from god there is two answers
0
10
False
True
You run a Python script named my_script.py directly from a terminal window.
In the script environment, what is the value of the `__name__` variable?
`__main__`
`__my_script__`
`my_script`
`my_script.py`
True or False: The containment operators in and not in return a True/False result.
True
False
You run a Python script named my_script.py by importing it as a module into a script named second_script.py.
In the script environment, what is the value of the `__name__` variable?
__main__
__my_script__
my_script
my_script.py
Which two statements are true for two objects that contain the same information and are saved in different memory locations?
Example:
```python
x = [1,2,3,a,b]
y = [1,2,3,a,b]
```
(Choose two.)
They are equal
They are not equal
They are identical
They are not identical
Which element stores Python script command-line arguments and options?
arg
argc
argparse
argv
Which Boolean operator has the highest precedence? (Choose one.)
and
not
or
Which Boolean operator has the highest precedence? (Choose one.)
or
is not
Which two statements about a positional argument are true? (Choose two.)
No answer text provided.
It is a required argument
It is an optional argument
It is always the first argument
Its position depends on the command
Which operator has the highest precedence? (Choose one.)
+
==
and
In Python, what is the base class for all built-in exceptions?
BaseException
Error
Exception
IOError
Which three data types can you use for dictionary keys? (Choose three.)
float
int
lists
other dictionaries
string
Which clause should you use for code that you want to execute regardless of whether an exception is raised?
else
elseif
except
finally
Which process does Python use to optimize dictionary search capabilities?
containment
hashing
iteration
looping
True or False: When handling exceptions, Python code can include an else clause or a finally clause, but not both.
True
False
In what format does a dictionary store information?
(key, value)
[key:value]
{key, value}
{key:value}
True or False: In Python, using the `raise` statement allows the programmer to define and raise their own exception.
True
False
Which two statements about key:value pairs are correct? (Choose two.)
Keys are unique
Values are unique
A value can be associated with multiple keys
Keys within a dictionary must be of the same type
Which of the following statements about tuples is true?
A tuple can contain list elements.
A tuple cannot contain another tuple.
After you define a tuple, you can add elements to it.
You define the elements of a tuple within square brackets.
In which two ways is a tuple like a list? (Choose two.)
Lists and tuples are data structures that can store a sequence of elements.
Lists and tuples are immutable data structures.
Lists and tuples can contain int, float, list, and string elements.
You can reorder the elements of lists and tuples.
Which string defines a heterogeneous tuple?
T = ("switch",)
T = tuple(L)
T = ("Tobias", 23, 25.3, [])
T = (10, -4, 59, 58, 23, 50)
Which process can you use to assign the values of a tuple to multiple variables?
Convert the tuple into a list
Create a homogeneous tuple
Slice the tuple
Unpack the tuple
When using printf-style string formatting, which conversion flag outputs a signed integer decimal?
%c
%d
%s
%x
Which attributes can you define for a time object? (Choose all that apply.)
Month
Day
Hour
Second
Millisecond
When using printf-style string formatting, which conversion flag outputs a single character?
%c
%d
%s
%x
What is the result of not setting the value of the year attribute of a date object?
The year defaults to 0.
The year defaults to the current year.
The year defaults to 9999.
The object is invalid.
When using the format() method, which placeholder outputs the variable x as a three-digit integer with two digits before and one digit after the decimal point (for example, 12.3)?
{x:2.1f}
{x:3.1f}
{x:3.2f}
{x:4.2f}
Which statement about the datetime.datetime data type is true?
All variables are optional.
All variables are required.
All date variables are required.
All time variables are required.
When using the str.format() method, which flag places a - (negative sign) in front of negative numbers?
"
^
-
+
True or False: Python code can include a script that returns the operating system platform your code is running on with the .sys
True
False
Which function displays a date object in the form Monday, January 01, 2018?
.strftime("%A, %B %d, %Y")
.strftime("%A, %B %D, %Y")
.strftime("%A, %M %d, %Y")
.strftime("%A, %M %D, %Y")
Which function can you use to list the contents of the current working directory?
os.chdir()
os.getcwd()
os.listdir()
os.rmdir()
Which type of statement should you use as a placeholder for future function code?
break
continue
pass
place
Which function can you use to delete an empty folder?
os.chdir()
os.getcwd()
os.listdir()
os.rmdir()
In an os function, which syntax can you use to move up one folder in the current directory structure?
/
\
\\
..
What type of loop should you use to repeat a code process as long as a condition resolves as `True`?
compound
for
nested
while
Which function can you use to test whether an absolute or relative path to a folder is valid?
os.path.commonpath(paths)
os.path.exists(path)
os.path.normpath(path)
os.path.realpath(path)
What type of loop should you use to iterate over the elements of a simple table (two-dimensional list)?
compound
for
nested
while
True or False: An infinite loop is a loop that runs until the value returned by the loop condition is False.
True
False
Which two os module functions can you use to delete a specific file? (Choose two.)
os.delete
os.path.re
os.remove
os.unlink
True or False: You can use the remove function to delete a specific file directory.
True
False
Which two functions can you use to determine whether a path leads to either a file or a directory? (Choose two.)
os.path.isdir(path)
os.path.isfile(path)
os.path.exists(file_path)
os.remove(file_path)
Which statement ensures that a file will be closed even when an exception is raised?
else: file.close()
file = open(file_path, mode)
file.close()
with open(file_path, mode) as file:
