Dump 2
Dump 2
(x, y)
[::1]
A developer needs to write code to reverse the [1::]
character output of a product code. Which variable
declaration will reverse one of the product codes?
[::-1]
[-1::]
x + y > 7 and x * y < 15
Analyze the following code:x = 5y = 3z = x + y > 7 z=
and x * y < 15 or x - y > 2Which expression is
performed last for calculating the value of z?
x - y > 2
x * y < 15 or x - y > 2
help(Example1)
You want to load the module Example1 and display Import Example1; help (Example1)
its documentation in the Python interpreter. Which
command should you use?
import Example
руthоn -m Example1
You are working on the code shown in the answer
area. You need to evaluate each operator and a=17b=5a/b
select the one whose result is the smallest
valueWhich operator should you use? To answer,
select the appropriate option.Choose the correct a=17b=5a+b
options
a=17b=5a*b
a=17b=5a%b
def division(a, b).return
a/btry:division(4.0)division("3","4")excep
t(ZeroDivisonError,TypeError) as
e:print(f'exception caught "%s" {e}')
try:division(4.0)division("3","4")except(E
rror,TypeError) as e:print('exception
You have the code shown in the answer area.You
need to add code to catch multiple exceptions in caught "%s" %e)dof division(a, b).istum
one exception block.Which line of code should you a/b
use? To answer, select the appropriate option from
the drop-down menu.Choose the correct options
try:division(4.0)division("3","4")except(Z
eroDivisor,TypeError) as
e:print('exception caught "%s" %e)def
division(a, b).return a/b
try:division(4.0)division("3","4")except(D
ivisorError,TypeError) as
e:print('exception caught "%s" %e)
datetime.datetime.today()
A developer is building a code block to log a
current date and time for app activity. Which two
code snippets will replace the #current date and datetime.datetime.strptime()
time comment with the correct date and
time?import datetimelog_time = #current date and datetime.datetime.now()
timeprint("entry time: ",log time)
datetime.datetime.strftime()
The proper syntax for pydoc is Python -m
pydoc module where module represents
the name of a Python module.
For each of the statements regarding pydoc, select
true if the statement is true and No if the statement
is false. Pydoc is a self-contained executable that
can be run from a command-line prompt.
31
You are writing code to have activity for every day
in a 30-day program. There should be no activity
on day 15.Using the dropdown arrows, fill in the continue
missing pieces to the code.
{select} dailyProgram in range(1, {select} ): 30
if dailyProgram == 15:
print("No activity on day 15")
{select} for
print(f"This is day {dailyProgram}")
else
break
You are writing code to list cities and then delete,
from the list, any city that has more than five letters len
in the name.Using the dropdown arrows, fill in the
missing pieces of code needed to complete the switch
code needed to fulfill this task.
cities = ['Anchorage', 'Juneau', 'Fairbanks',
'Ketchikan', 'Sitka', 'Wasilla'] cities
for city in cities:
if {select} (city) >; 5: remove
cities, {select} (city)
os
push
Choose the correct lines of code to satisfy the
needs of the following function:Students with
score >= 90:
scores of 90 or higher get an A.Students with
scores from 80 to 89 get a B.Students with scores score
from 70 to 79 get a C.Everyone else gets an F.
def grade(score):
if {select} score
grade = "A"
elif {select} score >= 70;
grade = "B"
elif {select}
grade = "C" grade = F:
else:
{select} grade = "F"
return grade
score >= 80
score == 70
Using the dropdown arrows for the missing code
pieces, complete the following code example so
that it accomplishes the functionality of this game:A
user gets five chances to correctly guess a whole
number from 1 to 10. If the user guesses correctly, from random import randint
they get a congratulatory message and the game
ends. If not, they get a message thanking them for
playing. from random import rand
{select} rand(1,10)
for i in range (5):
guess int(input("Enter a number from 1 to 10. "))
randNum = {select} randint(1,10)
if guess == randNum:
print("We matched!")
break
else: print("We did not match. Try again")
max
You have daily attendance figures for a conference min
and want to know the highest attendance for the
conference and the lowest attendance for the
conference.Using the dropdown arrows, fill in the {max}
missing code pieces necessary to obtain those
amounts. {min}
attendance [300, 250, 200, 400, 150, 225,325]
print ({select} (attendance))
print({select} (attendance)) min
max
You find errors while evaluating the following code. while (index
Line numbers are included for reference
only.numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]index =
0while (index < 10)print(numbers [index])if
if numbers [index] == 6;
numbers(index) = 6breakelse:index x+=1
Which code segment should you use at line 03? while (index
{select}
Which code segment should you use at line 06? if numbers [index] >= 6;
{select}
import
unittest. TestCase
You need to test whether an object is an instance
of a specific class.How should you set up the unit test isInstance(self)
test?Complete the code by selecting the correct
option from each drop-down list.Note: You will
receive partial credit for each correct selection. self assertisinstance(obj, cls, msg=None)
{select} unittest
class TestIsInstance( {select} ): export
def {select}:
{select}
if__name__ == '__main__': unittest. TestInstance
unittest.main()
test isInstance(test)
if
while
if
You are writing code to meet the following
requirementsAllow users to ropeuledly enter in
words.Output the number of characters in each
wordComplete the code by selecting the correct
option from each drop-downlistNote: You will while
receive partist credit for each correct selection
x = "Hello" if
{select} x != "QILI":
num = 0
{select} char {select} x: in
num +=1
print (num) while
x = input("Enter new word of Qull to exit: ")
if
in
Bread
The Script.py file contains the followingcodeimport
sysprint(sys.argv[2])You run the following Cheese
command:python Script.py Cheese Bacon
BreadWhat is the output of the command? Script.py
Bacon
You are writing a function to read a data file and
print the results as a formatted table. You write (0:10)
code to read a line of data into a list named
fields.The printout must be formatted to meet the
following requirementsFruit name (field [0]): Left- (1:5.1f)
aligned in a column 10 spaces wide.Weight
(fields[1]): Right-aligned in a column 5 spaces wide
with one digit after the decimal point.Price (2:7.2f)
(fields[2]): Right aligned in a column 7 spaces wide
with two digits after the decimal pointThe following {10:0}
shows a one-line sample of the output:Oranges 5.6
1.33
print(" {select} {select} {select} ", format(fields[0], {5:1f}
eval(fields[1]), rval(field [2])))
{7:2f}
Returns the current balance of the bank
accountdef get_balance():return balance