ITS Python Practice Exam 2 - Python
Programming with Complete Solutions
A developer is writing code to iterate prining and state, with the end result looking like
this:
Orange Florida
Orange Ohio
Orange Illinois
Springfield Florida
Springfield Ohio
Springfield Illinois
Capital
Auburn Florida
Auburn Ohio
Auburn Illinois
The first two lines of code are as follows:
cities=["Orange","Springfield","Auburn"]
states=["Florida","Ohio","Illinois"]
Using the dropdown arrows, complete the code necessary to generate the above
output. - ANSWER-for x in cities:
for y in states:
if x=="Springfield" and y=="Illionois":
A developer wants documentation for a function to display when called upon in a print
statement. Use the drop-down menus to fill in the remainder of the code necessary to
generate the documentation. - ANSWER-'''
'''
area.__doc__
A developer wants to print the first line of a configuartion file. The code to perform this
tast is written as follows:
#import module
if os.path.isfile('config.txt;):
with open('config.txt','r') as file:
print(file.#read the first line)
Which code snippets are needed to replace the comments and finish this code
example? - ANSWER-readline()
import. os.path
A junior programmer enters the following code:
height=5
width=5
, if height==width
print("You have a square")
When trying to run the code, errors are generated. Which two fixes are necessary in
order for this code to work? - ANSWER-A colon needs to be added at the end of the if
condition.
The print statement needs to be indented.
A junior programmer is building a function to compute the area of a rectangle. Which
function definition statement is needed to replace the comment to make this code work?
#declare function here
z=x*y
print(z)
area(5,10) - ANSWER-def area(x,y):
A junior programmer writes the following code to store a list and then retrieve an item
from the list:
tees=['Douglas fir','Oak','Balsam fir']
last_tree=trees[3]
print(f'The last tree is {last_tree}.')
What type of error message (if this code generates an error) will this code produce? -
ANSWER-A runtime error
A new Python developer is learning the code necessary to display dates in multiple
formats. The developer has been tasked to create the following display with dates:
2023-01-01
The current date is 01/01/2023
The current weekday is: 6
Using the dropdown arrows, complete the code snippet necessary to create the display,
leaving open the possibility of the time being displayed in the future. - ANSWER-import
datetime
datetime,datetime.now()
%m/%d/%Y
weekday()
A new Python developer is trying to understand the differences among data structures.
Using drag and drop, match each code example with a characteristic of the type of list
being generated from the code. - ANSWER-
background_colors=['yellow','slate','lightblue']
locations={'HQ','West','Remote1'}
departments=('Sales','Marketing','Operations','IT')
offices={'location':'East','size':'4500'}
Programming with Complete Solutions
A developer is writing code to iterate prining and state, with the end result looking like
this:
Orange Florida
Orange Ohio
Orange Illinois
Springfield Florida
Springfield Ohio
Springfield Illinois
Capital
Auburn Florida
Auburn Ohio
Auburn Illinois
The first two lines of code are as follows:
cities=["Orange","Springfield","Auburn"]
states=["Florida","Ohio","Illinois"]
Using the dropdown arrows, complete the code necessary to generate the above
output. - ANSWER-for x in cities:
for y in states:
if x=="Springfield" and y=="Illionois":
A developer wants documentation for a function to display when called upon in a print
statement. Use the drop-down menus to fill in the remainder of the code necessary to
generate the documentation. - ANSWER-'''
'''
area.__doc__
A developer wants to print the first line of a configuartion file. The code to perform this
tast is written as follows:
#import module
if os.path.isfile('config.txt;):
with open('config.txt','r') as file:
print(file.#read the first line)
Which code snippets are needed to replace the comments and finish this code
example? - ANSWER-readline()
import. os.path
A junior programmer enters the following code:
height=5
width=5
, if height==width
print("You have a square")
When trying to run the code, errors are generated. Which two fixes are necessary in
order for this code to work? - ANSWER-A colon needs to be added at the end of the if
condition.
The print statement needs to be indented.
A junior programmer is building a function to compute the area of a rectangle. Which
function definition statement is needed to replace the comment to make this code work?
#declare function here
z=x*y
print(z)
area(5,10) - ANSWER-def area(x,y):
A junior programmer writes the following code to store a list and then retrieve an item
from the list:
tees=['Douglas fir','Oak','Balsam fir']
last_tree=trees[3]
print(f'The last tree is {last_tree}.')
What type of error message (if this code generates an error) will this code produce? -
ANSWER-A runtime error
A new Python developer is learning the code necessary to display dates in multiple
formats. The developer has been tasked to create the following display with dates:
2023-01-01
The current date is 01/01/2023
The current weekday is: 6
Using the dropdown arrows, complete the code snippet necessary to create the display,
leaving open the possibility of the time being displayed in the future. - ANSWER-import
datetime
datetime,datetime.now()
%m/%d/%Y
weekday()
A new Python developer is trying to understand the differences among data structures.
Using drag and drop, match each code example with a characteristic of the type of list
being generated from the code. - ANSWER-
background_colors=['yellow','slate','lightblue']
locations={'HQ','West','Remote1'}
departments=('Sales','Marketing','Operations','IT')
offices={'location':'East','size':'4500'}