Question Bank - Python
Question Bank - Python
Question 3
This question requires that you evaluate the underlined text to determine if it is correct.
You write the following code:
The out.txt file does not exist You run the code. The code will execute without error.
import sys
try:
file_in = open("in.txt",'r')
file_out = open("out.txt",'w+')
except IOError:
print('cannot open',file_name)
else:
i=l
for line in file_in:
print(line.rstrip())
file_out.write("line " + str(i) + ":" + line)
i = i+ 1
file_in.close()
file_out.close()
lOM oAR c P S D | 982 04 78
Answer Area
A. No change is needed.
B. The code runs,but generate a logic error.
C. The code will generate a runtime error.
D. The code will generate a syntax error
Question 4
Relecloud Virtual Learning asks you to debug some code that is causing problems with their
payroll. They ask you to find the source of the payroll errors. The following variables have been
declared:
Which code should you use to fix the errors? To answer, select the appropriate code segments
in the answer area.
Answer Area
for index in range 1................
count +=1
sum += employee_pay[index]
average = .2..............
print("The total payroll is:", sum )
1)
A. (size(employee_pay)):
lOM oAR c P S D | 982 04 78
B. (size(employee_pay)-1):
C. (len(employee_pay)+1):
D. (len(employee_pay)):
2)
A. sum/count
B. sum**count
C. sum*count
Question 5
You develop a Python application for your company.
How should you complete the code so that the print statements are accurate? To answer. select
the appropriate code segments in the answer area.
Answer Area
numList =[1,2,3,4,5]
alphaList=["a","b","c","d","e"]
1................................
2....................................
1)
A. if numList==alphaList:
A. B if numList==alphaList
B. else:
lOM oAR c P S D | 982 04 78
C. else
2)
A. if numList==alphaList:
A. B if numList==alphaList
B. else:
C. D.else
Question 6
You are writing a function in Python that must meet the following requirements:
In which order should you arrange the code segments to develop the solution? To answer, move
all code segments from the list of code segments to the answer area and arrange them in the
correct order.
Answer Area
A - for i in range(len(items)):
B - if items[i]==term:
print("{0} was found in the list.".format(term))
C - break
lOM oAR c P S D | 982 04 78
D - def search(items,term):
E -
else:
print("{0} was not found in the list." .format(term))
A. D,A,B,C,E
B. D,B,A,C,E
C. B,D,A,C,E
D. D,A,B,E,C
Question 7
You are writing a Python program to ask the user to enter a number and determine if the
number is 1 digit 2 digits, or more than 2 digits long.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Answer Area
1------------------------
digits = "1"
2......................................................
lOM oAR c P S D | 982 04 78
digits= 2
.3...................................................
digits= ">2"
1.
A. if num > - 10 and num < 10:
B. lif num> - 100 and num < 100:
2.
A. if num > -100 and num < 100:
B. elif num >-100 and num < 100:
C. if num >-10 and num < 10:
D. elif num >-10 and num <10:
3.
A. else:
B. elif:
Question 8
Wingtip Toys is creating an interactive Times Table Helper program intended for elementary
school children.
You need to complete a function that computes and displays all multiplication table
combinations from 2 to 12.
How should you complete the code? To answer, select the appropriate code segments in the
answec area,
Answer Area
def times_tables():
1-------------------------
2-------------------------
print(row*col,end=" ")
print()
#main
times_tables()
1)
2)
Question 9
Adventure Works Cycles sales are so exceptional that they decide to give a bonus to all
employees who do not make more than $150,000. The following formula applies to each
employee based on their base salary and a flat bonus:
You need to complete the code that applies an increase to each eligible employee’s salary.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Answer Area
salary_list=[150000,340000,230000,500000,100000,120000,90000]
1...................................
if salary_list[index] >=150000:
2............................................
1)
2)
A. exit()
B. continue
C. break
D. end
Question 10
You are creating a Python program that will let a user guess a number from 1 to 10. The user is
allowed up to three guesses.
You write the following code. Line numbers are included for reference only.
The program must allow three guesses. If the user guesses the correct number, the program
must stop asking for guesses.
How should you complete lines 05, 13, and 14? To answer, drag the appropriate code segments
lOM oAR c P S D | 982 04 78
to the correct locations. Each code segment may be used once, more than once, or not at all.
You may need to drag the split bar between panes or scroll to view content.
Answer Area
B. break F pass
D. chance = 2
B. break F pass
D. chance = 2
B. break F pass
D. chance = 2
Question 11
You are creating a function to calculate admission fees by using Python. Admission fees are
calculated based on the following rules:
lOM oAR c P S D | 982 04 78
Answer Area
admission_fee(age, school):
rate =0
.1.................................
rate =10
.2....................................
3 ....................................
rate =20
1)
2).
3).
C. if age <=17:
Question 12
You work on a team that is developing a game for AdventureWorks.
You need to write code that generates a random number that meets the following
requirements:
Which two code segments will meet the requirements? Each correct answer presents a
complete solution. Choose two.
Answer Area
A. from random import randrange
print(randint(0, 20)*5)
print(randint(1, 20)*5)
Question 13
You write a function that reads a data file and prints each line of the file. You write the following
code. Line numbers are included for reference only.
01 def read_file(file):
02 line= None
03 if os.path.isfile(file):
04 data = open(file,'r')
05 for line in data:
06 print(line)
When you run the program, you receive an error on line 03.
Answer Area
A. The path method does not exist in the os object.
B. You need to import the os library.
C. The isfile method does not exist in the path object.
D. The isfile method does not accept one parameter.
Question 14
You need to write code that generates a random float with a minimum value of 0.0 and a
maximum value of 1.0. Which statement should you use?
Answer Area
A. rando.randrange(0.0, 1.0)
B. random.randrange()
C. random.random()
D. random.randint(O, 1)
lOM oAR c P S D | 982 04 78
Question 16
You are writing a function that increments the player score in a game.
The function has the following requirements:
• If no value is specified for points, then points start at one
• If bonus IS True, then points must be doubled
You write the following code. Line numbers are included for reference only.
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Note: Each correct selection is worth one point.
Answer Area
A. yes
B. No
A. yes
B. No
lOM oAR c P S D | 982 04 78
Once any parameter is defined with a default value, any parameters to the right must also be
defined with default values.
A. yes
B. No
If the function is called with only two parameters, the value of the third parameter will be None.
A. yes
B. No
Line 03 will also modify the value of the variable points declared at line
Question 17
You are developing a Python application for an online game.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Answer Area
1) .............................. 2) .................................
current+=value
lOM oAR c P S D | 982 04 78
3)..............................
1)
A. update_score
B. def update_score
C. return update_score
2)
A. (current,value):
B. ():
C. (current,value)
A. D.()
3)
A. pass current
B. return current
C. return
D. pass
Question 18
Woodgrove Bank is migrating their legacy bank transaction code to Python.
You have been hired to document the migrated code.
Which documentation syntax is correct?
Answer Area
A. ' Returns the current balance of the bank account
def get_balance():
return balance
B. def get_balance():
#Returns the current balance of the bank account
lOM oAR c P S D | 982 04 78
return balance
c. def get_balance():
return balance
def get_balance():
return balance
Question 19
You are writing a Python application for a dance studio.
The studio wants to encourage youth and seniors to sign up. Minors and seniors must receive a
10% discount.
You write the following code. Line numbers are included for reference only.
Answer Area
Question 20
A classmate has asked you to debug the tollowing code:
x=4
while x >= 1:
if x % 4 == 0:
print ("party")
elif x - 2 < 0:
print("cake")
elif x/3 == 0:
print("greeting")
else:
print("birthday")
x=x-1
Answer Area
A. birthday
party
greeting
cake
B. party
greeting
birthday
cake
c. birthday
lOM oAR c P S D | 982 04 78
greeting
party
cake
D. party
birthday
birthday
cake
Question 21
You write the following code:
a='Configl'
print(a)
b=a
a + = Config2
print(a)
print(b)
Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code segment.
Answer Area
What is displayed after the first print?
A. A.Config1
B. Config1Config2
C. C.Config2
A. A.Config1
B. Config1Config2
C. C.Config2
lOM oAR c P S D | 982 04 78
A. A.Config1
B. Config1Config2
C. C.Config2
Question 22
you Write the following code:
list_ 1 = [1, 2]
list_2 = [3, 4]
list_3 = list_1 + list_2
list_4 = list_3*3
print(list_4)
Answer Area
A. [[1,2], [3,4],[1,2],[3,4],[1,2],[3,4]]
B. [[1,2,3,4], [1,2,3,4],[1,2,3,4]]
C. [3,6,9,12]
D. [1,2,3,4,1,2,3,4,1,2,3,4]
Question 23
You develop a Python application for your school.
A list named colors contains 200 colors. You need to slice the list to display every other color
starting with the second color.
Answer Area
lOM oAR c P S D | 982 04 78
A. colors[1::2]
B. colors[1:2]
C. colors[2:2]
D. colors[::2]
Question 24
You are creating a Python program that compares numbers.
You create the following code. Line numbers are included for reference only.
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Answer Area
The print statement at line 04 will only print if the two numbers are equal in value.
A. Yes
B. NO
lOM oAR c P S D | 982 04 78
The print statement at line 06 will only print if num1 is less than num2.
A. Yes
B. NO
The print statement at line 08 will only print if num1 is greater than num2.
A. Yes
B. NO
A. Yes
B. NO
Question 25
Answer Area
A. 4
B. False
C. True
D. 5
lOM oAR c P S D | 982 04 78
Question 26
A coworker wrote a program that inputs names into a database. Unfortunately, the program
reversed the letters in each name.
You need to write a Python function that outputs the characters in a name in the correct order.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Answer Area
forward_name += 2).............................
return forward_name
1)
A. backwards_name:
B. len(backwards_name):
C. range(0,len(backwards_name)-1):
D. range(len(backwards_name)-1,-1,-1):
2)
A. backwards_name[index-1]
B. backwards_name[len(forward_name)-1]
C. backwards_name[len(backward_name)-len(forward_name)]
D. backwards_name[index]
lOM oAR c P S D | 982 04 78
Question 27
Woodgrove Bank must generate a report that shows the average balance for all customers each
day. The report must truncate the decimal portion of the balance.
Which two code segments should you use? Each correct answer presents a complete solution.
Choose two.
Answer Area
A. average_ba1ance = total_deposits**number_of_customers
B. average_balance = int(total_deposits/number_of_customers)
C. average_balance = total_deposits//number_of_customers
D. average_balance = float(total_deposits//number_of_customers)
Question 28
You have the following code. line numbers are included for reference only.
01 def main(a,b,c,d):
02 value = a+b*c-d
03 return value
Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code segment.
lOM oAR c P S D | 982 04 78
Answer Area
A. a+b
B. b*c
C. c-d
A. addition
B. Subtraction
A. (a+b)*(c-d)
B. (a+(b*c))-d
C. a+((b*c)-d)
Question 29
You are writing a function to perform safe division.
You need to ensure that a denominator and numerator are passed to the function and that the
denominator is not zero.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Answer Area
1).......................
2)........................
else:
1)
A. if numerator is None or denominator is None:
B. if numerator is None and denometor is None:
C. if numerator = None or denominator =None
D. if numerator = None and denominator = None:
2)
Question 30
lOM oAR c P S D | 982 04 78
You are writing a function that returns the data type of the value that Is passed in. You write the
following code. Line numbers are included for reference only.
01 def checkType(value):
02 dataType = type(value)
03 return dataType
04 print(checlcType(True))
05 print(checkType(1.0))
06 print (checkType(1))
07 print(checkType("True"))
Use the drop-down menus to select the answer choice that answers each question based on the
information presented in the code segment
Answer Area
Question 31
You are developing a Python program that compares numbers.
You need to ensure that you are using the correct comparison operators.
Evaluate each expression and indicate the correct result. To answer, drag the appropriate result
from the column on the left to its expression on the right. Each result may be used once, more
than once, or not at all.
Answer Area
1) . 0 or 5
A. True
B. False
C. 5
D. None
2). bool(0)
A. True
B. False
C. 5
D. None
lOM oAR c P S D | 982 04 78
A. True
B. False
C. 5
D. None
4). -5 < 0 <5
A. True
B. False
C. 5
D. None
Question 32
You are writing a program that calculates a user’s year of birth. The program asks users for their
age and the current year, then outputs the users year of birth, You write the following code. Line
numbers are included for reference only.
You need to ensure that the program uses the appropriate data types.
What data types are used? Use the drop-down menus to select the answer choice that answers
each question based on the information presented in the code segment.
Answer Area
A. int
B. str
lOM oAR c P S D | 982 04 78
C. float
D. bool
A. int
B. str
C. float
D. bool
A. int
B. str
C. float
D. bool
Question 33
You have the following list structure:
aiph = “abcdefghijklmnopqrstuvwxyz”
Match the result to the slicing operation. To answer, drag the appropriate result from the
column on the left to its slicing operation on the right. Each result may be used once, more than
once, or not at all.
lOM oAR c P S D | 982 04 78
Answer Area
alph[3:15]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
alph[3:15:3]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
alph[3:15:-3]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
lOM oAR c P S D | 982 04 78
alph [15:3:-3]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
alph[15:3]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
alph[::-3]
A. zwtqnkheb
B. pmjg
C. defghijklmno
D. ponmlkjihgfe
E. defghijklmnop
F. dgjm
G. olif
H. ""
Question 34
lOM oAR c P S D | 982 04 78
You are writing a Python program. The program collects customer data and stores it in a
database.
Match the data type to the code segment. To answer, drag the appropriate data type from the
column on the left to its code segment on the right. Each data type may be used once, more
than once, or not at all.
Answer Area
age =2
A. bool
B. float
C. int
D. str
minor=False
A. age =2
B. bool
C. float
D. int
E. str
name = "Contoso"
A. age =2
B. bool
C. float
D. int
E. str
weight = 123.5
A. age =2
B. bool
lOM oAR c P S D | 982 04 78
C. float
D. int
E. str
zip ="81000"
A. age =2
B. bool
C. float
D. int
E. str
Question 35
Northwind Electric Cars needs help updating their file system using Python code. You must
create a simple file manipulation program that performs the following actions:
How should you complete the code? To answer. select the appropriate code segments in the
answer area.
Answer Area
lOM oAR c P S D | 982 04 78
Question 38
import datetime
d = datetime.datetime(2017, 4, 7)
print('{:%B-%d-%y}' .format(d))
num=1234567.890
print({:,.4f)' .format(num))
You run the program.
Answer Area
A. Apr--07--2017
1,234,567.8900
Press any key to continue..
B. April--07--17
1.234,567.8900
Press any key to continue...
C. April--07--17
1234567.89
Press any key to continue...
D. 2017--ApriI--07
1,234,567.890
Question 39
lOM oAR c P S D | 982 04 78
You are writing a function to read a data file and print the results as a formatted table.
The data file contains information about fruit. Each record contains the name of the fruit, the
weight, and the price.
You need to print the data so that it looks like the following sample:
You write the following code. Line numbers included are for reference only.
01 def print_table(file):
02 data - open(file,'r')
03 for record in data:
04 fields = record.split(",")
How should you complete line 05? To answer, drag the appropriate code segments to the
correct location. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
Answer Area
1).
A. print("
B. {10:0}
C. {5:1f}
D. {7:2f}
E. {2:7.2f}
F. {1:5.1f}
lOM oAR c P S D | 982 04 78
G. {0:10}
2)
A. print("
B. {10:0}
C. {5:1f}
D. {7:2f}
E. {2:7.2f}
F. {1:5.1f}
G. {0:10}
3)
A. print("
B. {10:0}
C. {5:1f}
D. {7:2f}
E. {2:7.2f}
F. {1:5.1f}
G. {0:10}
4)
A. print("
B. {10:0}
C. {5:1f}
D. {7:2f}
E. {2:7.2f}
F. {1:5.1f}
G. {0:10}
Question 40
lOM oAR c P S D | 982 04 78
Tailspin Toys is building a basketball court for its employees to improve company morale.
You are creating a Python program that employees can use to keep track of their average score.
The program must allow users to enter their name and current scores. The program will output
the user name and the users average score. The output must meet the following requirements:
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Answer Area
score =0
count =0
Sum = 0
while(score !=-1):
score =int(input("Enter your scores:(-1 to end)"))
if score == -1:
break
Sum+=score
count +=1
average_score =Sum/count
print(" 1)............., your average score is: 2) ............................. "% (name, average))
lOM oAR c P S D | 982 04 78
1)
A. %-20i
B. %-20d
C. %-20f
D. %-20s
2)
A. %1.4s
B. %4.1f
C. %4.1S
D. %1.4f
Question 1.
The employee number must have the format ddd-dd—dddd and consist only of
numbers and dashes. The program must print True if the format is correct and
print False if the format is
incorrect.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
lOM oAR c P S D | 982 04 78
Answer Area
employee_number=""
parts =" "
while employee_number!="":
valid =True
employee_number = input("Enter employee number (ddd-dd-dddd): ")
parts = employee_number.split('-')
if len(parts)==3 :
if len(parts[0]) ==3 and len(parts[1])==2 and len(parts[2]) ==4 :
if parts[0].isdigit() and parts[1].isdigit() and parts[2].isdigit():
valid=False
print(valid)
Question 2.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
lOM oAR c P S D | 982 04 78
def safe_root(a,b):
1.................
answer =a**(1/b)
2.................
3 ..............
4...............
answer= -(-a)**(1/b)
return answer
Q - section 1
A. If a>=0:
B. If a %2==0:
C. else:
D. elif:
Q - section 2
A. If a>=0:
B. If a %2==0:
C. else:
D. elif:
Q - section 3
A. If a>=0:
B. If a %2==0:
C. else:
D. elif:
lOM oAR c P S D | 982 04 78
Q - section 4
A. If a>=0:
B. If a %2==0:
C. else:
D. elif:
Question 3.
You work for a company that distributes media for all ages.
You are writing a function that assigns a rating based on a user's age. The function
must meet the following requirements:
Answer Area
def get_rating(age):
rating =""
1………………………
2........................
3………………………
4………………………
return rating
lOM oAR c P S D | 982 04 78
Q - section 1
Q - section 2
Q - section 3
Q - section 4
Question 4.
table:
90 through 100 A
80 through 89 B
70 through 79 C
65 through 69 D
O through 64 F
For example, if the user enters a 90, the output should be, "Your letter grade is A."
Likewise, if a user enters an 89, the Output should be "Your letter grade is B."
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
1…………………………………..
letter_grade = ‘A’
2…………………………………...
letter_grade = ‘B’
3…………………………………….
lOM oAR c P S D | 982 04 78
Letter_grade =’C’
4……………………………………..
Letter_grade = ‘D’
Else:
Letter_grade =’F’
Q - section 1
A. If grade <=90:
B. If grade >=90:
C. elif grade >90:
D. elif grade >=90:
Q - section 2
A. If grade <=80:
B. If grade >=80:
C. elif grade >80:
D. elif grade >=80:
Q - section 3
A. If grade <=70:
B. If grade >=70:
C. elif grade >70:
D. elif grade >=70:
Q - section 4
A. If grade <=65:
B. If grade >=65:
C. elif grade >65:
D. elif grade >=65:
lOM oAR c P S D | 982 04 78
Question 5
You need the program to iterate through a list of products and escape when a
target product D is found.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
produceIdList =[ 0,1,2,3,4,5,6,7,8,9]
index =0
1. ..............(index <10):
print (ProductIdList[index])
if productIdList[index]==6:
2...................
else:
index+=1
Q - section 1
A. While
B. For
C. If
lOM oAR c P S D | 982 04 78
D. break
Q - section 2
A. While
B. For
C. If
D. break
Question 6
You are building a python program that displays all of the prime numbers from 2
to 100.
How should you complete the code? To answer, drag the appropriate code
segments to the correct location. Each code segment may be used once, more
than once, or not at all.
You may need to drag the split bar between panes or scroll to view content.
Question 7
You are creating a Python script to evaluate input and check for upper and lower
case.
Which four code segments should you use to develop the solution? To answer,
move the appropriate code segment from the list of code segments to the answer
area and arrange them in the correct order.
Code Segments
A.
else:
lOM oAR c P S D | 982 04 78
B.
else:
print(name, “is lower case.”)
C.
D.
else:
print(name, “is upper case.”)
E.
F.
if name.lower()==name:
print(name, “is all lower case.”)
lOM oAR c P S D | 982 04 78
A. C,F,E,A
B. C,E,F,A
C. E,C,D,B
D. C,B,D,A
Question 8
You have the following code. Line numbers are included for reference only.
def main(a,b,c,d):
value = a+b*c-d
return value
Use the drop-down menus to select the answer choice that answers each
question based on the information presented in the code segment.
Answer Area
A. Addition
B. subtraction
A. (a+b)*(c-d)
B. (a+(b*c))-d
C. a+((b*c)-d)
Question 9
Northwind Traders has hired you as an intern on the coding team that creates e-
commerce appications,
You must write a script that asks the user for a value. The value must be used as a
whole number in a calculation, even if the user enters a decimal value.
Answer Area
Question 10
lOM oAR c P S D | 982 04 78
You create the following program to locate a conference room and display the
room name. Line numbers are included for reference only.
else :
You need to troubleshoot the program. Use the drop-down menus to select the
answer choice that answers each question based on the information presented in
the code segment.
Answer Area
Which two data types are stored in the rooms list at line 01?
Question 11
You want to introduce the concept of data types in Python. You create the
following three code segments:
#Code segment 1
X1 = “20”
Y1 = 3
a = x1 * y1
# Code segment 2
x2 = 6
Y2 = 4
B= x2 / y2
# Code Segment 3
x3 = 2.5
y3 = 1
c=x3 / y3
lOM oAR c P S D | 982 04 78
For each of the following statements, select Yes if the statement is true.
Otherwise, select No.
Answer Area
A. Yes
B. NO
Question 12
To answer, drag the appropriate data type to the correct type operation. Each data
type may be used once, more than once, or not at all.
Answer Area
lOM oAR c P S D | 982 04 78
1. type(+1E10)
A. int
B. float
C. str
D. bool
2. type(5.0)
A. int
B. float
C. str
D. bool
3. type(“True”)
A. int
B. float
C. str
D. bool
4. type(False)
A. int
B. float
C. str
lOM oAR c P S D | 982 04 78
D. bool
Question 13
Luceme Publishing Company needs a way to find the count of particular letters in
their publications to ensure that there is a good balance. It seems that there have
been complaints about overuse of the letter e. You need to create a function to
meet the requirements.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
def count_letter(letter,word_list):
count=0
for 1..............
if 2............
count +=1
return count
word_list =[]
#word_list is populated a from file. code not shown
Q - section 1
A. word_list in word:
B. Word in word_list:
C. Word ==word_list:
D. Word is word_list:
Q - section 2
A. Word is letter:
B. Letter is word:
C. Word in letter:
D. Letter in word:
Question 14
Southridge Video needs a way to determine the cost that a customer will pay for
renting a DVD. The cost is dependent on the time of day the DVD is retumed.
How'ever, there are also special rates on Thursdays and Sundays. The fee structure
's shown in the following list:
Answer Area
Question 15
lOM oAR c P S D | 982 04 78
What is the correct order of operations for the six classes of operations ordered
from first to last in order of precedence? To answer, move all operations from the
ist of operations to the
Answer Area
Operations
A. Parenthesis 1
B. Exponents 2
C. Add 6
D. Multiplication and Division 4
E. Addition and Subtraction 5
F. Unary positive,negative,not 3
Question 16
lOM oAR c P S D | 982 04 78
You are writing a Python program. The program collects customer data and stores
it in a database.
You need to ensure that the program handles the data correctly so that it can be
stored in the database correctly.
Match the data type to the code segment. To answer, drag the appropriate data
type from the column on the left to its code segment on the right. Each data type
may be used once, more than once, or not at al.
Answer Area
Q1. Age =2
A. Bool
B. Float
C. Int
D. Str
Question 17
You need to calculate the number of years of service and print a congratulatory
message.
You have written the following code. Line numbers are included for reference only.
Answer Area
Question 18
numList=[1,2,3,4,5]
alphaList = ["a","b","c","d","e"]
print(numList is alphaList)
print(numList == alphaList)
numList = alphaList
print(numList is alphaList)
print(numList ==alphaList)
use the drop-down menus to select the answer choice that answers each question
based on the information presented in the code segment.
lOM oAR c P S D | 982 04 78
Answer Area
A. True
B. False
A. True
B. False
Question 19
a=11
b=4
lOM oAR c P S D | 982 04 78
What is the result of each arithmetic expression? To answer, drag the appropriate
expression from the column on the left to its result on the right Each expression
may be used once, more than once, or not at al.
Answer Area
Q 1. 2
A. Print(a/b)
B. Print(a//b)
C. Print(a%b)
Q 2. 3
A. Print(a/b)
B. Print(a//b)
C. Print(a%b)
Q 3. 2.75
A. Print(a/b)
B. Print(a//b)
C. Print(a%b)
Question 20
You create the following code segment. Line numbers are included for reference
only.
How should you complete the code on line 02? To answer, drag the appropriate
code segment to the correct location. Each code segment may be used once,
more than once, or not at all. You may need to drag the split bar between panes
or scroll to view content.
Question 21
(3*(1+2)**2 – (2**2)*3)
Answer Area
lOM oAR c P S D | 982 04 78
A. 3
B. 13
C. 15
D. 69
Question 22
A list named employees contains 200 employee names, the last five being
company management. You need to slice the list to display all employees
excluding management.
Which two code segments should you use? Each correct answer presents a
complete solution. Choose two.
Answer Area
A. employees [1:-4]
B. employees [:-5]
C. employees [1:-5]
D. employees [0:-4]
E. employees [0:-5]
lOM oAR c P S D | 982 04 78
Question 23
You are an intern for Northwind Electric Cars. You must create a function that
calculates the average velocity of their vehicles on a 1320 foot (1/4 mile) track.
The output must be as precise as possible.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
#Speed calculator
velocity = distance_miles/time_hours
Q - section 1
A. int
B. str
C. float
Q - section 2
lOM oAR c P S D | 982 04 78
A. int
B. float
C. str
Question 24
You are creating a function that manipulates a number. The function has the
following requirements:
Answer Area
A. Math.fmod(x)
B. Math.frexp(x)
C. Math.floor(x)
D. Math.ceil(x)
E. Math.fabs(x)
Question 25
lOM oAR c P S D | 982 04 78
You are writing an application that uses the sqrt function. The program must
reference the function using the name squareRoot.
Answer Area
Question 26
You are writing code that generates a random integer with a minimum value of S
and a maximum value of 11.
Which two functions should you use? Each correct answer presents a complete
solution. Choose two.
Answer Area
A. random.randint(5,12)
lOM oAR c P S D | 982 04 78
B. random.randint(5,11)
C. random.randrange(5,12,1)
D. random.randrange(5,11,1)
Question 27
You need to ensure that the function returns None if the file does not exist If the
file does exist, the function must return the first line.
import os
def get_first_line(filename,mode):
In which order should you arrange the code segments to complete the function?
To answer, move all code segments from the list of code segments to the answer
area and arrange them in the correct order.
If os.path.isfile(filename):
return file.readline()
return None
else:
Question 28
You are writing a Python program to automate inventory. Your first task is to read
a file of inventory transactions. The file contains sales from the previous day,
including the item id, price, and quantity.
10, 200, 5
20, 100, 1
eof =False
line = inventory.readline()
.................
.................:
print(line)
else:
eof=True
inventory.close()
which code should you write for line 05 and line 06?
A. 05 if line != ’\n’:
06 if line ! =””:
B. 05 if line !=’\n’:
06 if line ! =None:
lOM oAR c P S D | 982 04 78
C. 05 if line ! = ‘ ‘:
06 if line ! = “”:
D. 05 if line != ‘ ‘:
06 if line != “\n”:
Question 29
You need to accept input from the user and print that information to the user
screen.
You have started with the following code. Line numbers are included for reference
only.
Answer Area
A. name =input
B. input(“name”)
lOM oAR c P S D | 982 04 78
C. input(name)
D. name =input()
Question 30
You need to read and write data to a text file. If the file does not exist, it must be
created. If the file has content, the content must be removed.
Question 31
Best For You Organics Company needs a simple program that their call center will
use to enter survey data for a new coffee variety.
The program must accept input and return the average rating based on a five-star
scale. The output must be rounded to two decimal places.
lOM oAR c P S D | 982 04 78
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
sum=count =done=0
average =0.0
if rating == -1:
break
sum+=rating
count+=1
averge =float(sum/count)
2....................... + 3.....................
Q –section 1
Q –section 2
lOM oAR c P S D | 982 04 78
Q –section 3
a. format(average,’.2f))
b.
c. format(average,’.2d'))
d. {average,'.2f}
e. format.average.{2d}
Question 32
Tailspin Toys is building a basketball court for its employees to improve company
morale.
You are creating a Python program that employees can use to keep track of their
average score.
The program must allow users to enter their name and current scores. The
program will output the user name and the users average score. The output must
meet the following requirements:
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
NOTE: Each correct selection is worth one point.
Answer Area
score =0
count =0
Sum = 0
while(score !=-1):
score =int(input("Enter your scores:(-1 to end)"))
if score == -1:
break
Sum+=score
count +=1
average_score =Sum/count
Q –section 1
E. %-20i
F. %-20d
G. %-20f
H. %-20s
lOM oAR c P S D | 982 04 78
Q –section 2
E. %1.4s
F. %4.1f
G. %4.1S
H. %1.4f
Question 33
You find errors while evaluating the following code. Line numbers are included for
reference only.
01 numbers = [0,1,2,3,4,5,6,7,8,9]
02 index =0
03 while (index <10)
04 print(numbers[index])
05
06 if numbers(index)=6
07 break
08 else:
09 index +=1
How should you correct the code? Use the drop-down menus to select the answer
choice that answers each question based on the information presented in the
code segment.
Answer Area
A. While(index <10):
B. While[index <10]
C. While(index <5):
D. While[index <5]
Question 34
You are creating a function that reads a data file and prints each line Of the file.
You write the following code. Line numbers are included for reference only.
01 import os
02 def read_file(file):
03 line = None
04 if os.path.isfile(file):
05 data =open(file, 'r')
06 while line != ' ':
07 line = data.readline()
lOM oAR c P S D | 982 04 78
08 print(line)
The code attempts to read the file even if the file does not exist.
Answer Area
A. Line 01
B. Line 02
C. Line 03
D. Line o4
E. Line 05
F. Line 06
G. Line 07
H. Line 08
lOM oAR c P S D | 982 04 78
Question 35
This question requires that you evaluate the underlined text to determine if it is
correct.
You write the following code:
import sys
try:
file_in = open("in.txt",'r')
file_out = open("out.txt",'w+')
except IOError:
print('cannot open',file_name)
else:
i=l
for line in file_in:
print(line.rstrip())
file_out.write("line " + str(i) + ":" + line)
i = i+ 1
file_in.close()
file_out.close()
The out.txt file does not exist You run the code. The code will execute without
error.
Review the underlined text. If it make the statement correct,select “No change is
needed.” If the statement is incorrect ,select the answer choice that make the
statement correct.
Answer Area
E. No change is needed.
F. The code runs,but generate a logic error.
G. The code will generate a runtime error.
H. The code will generate a syntax error
lOM oAR c P S D | 982 04 78
Question 36
Answer Area
Question 37
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
1) .............................. 2).................................
Current+=value
3)..............................
Q –section 1
D. update_score
E. def update_score
F. return update_score
Q –section 2
D. (current,value):
E. ():
F. (current,value)
B. D.()
Q –section 3
lOM oAR c P S D | 982 04 78
E. pass current
F. return current
G. return
H. pass
Question 38
You develop a Python application for your company.
You want to add notes to your code so other team members will understand it.
Answer Area
B.
C. Place the notes after the last line of code separated by a blank line.
D.
E. Place the notes before the first line Of code separated by a blank line.
F.
G. Place the notes inside of parentheses on any line.
Question 39
Adventure Works Cycles is creating a program that allows customers to log the
number Of miles biked. The program will send messages based on how many
lOM oAR c P S D | 982 04 78
You create the following Python code. Line numbers are included for reference
only.
01
02 name = input("What is your name?")
03 return name
04
05 calories = miles * calories_per_mile
07 return calories
08 distance =int(input("How many miles did you bike this week? "))
09 burn_rate = 50
10 bikar = get_name()
11 calories_burned = calc_calories(distance, burn_rate)
12 print(bikar, ", you burned about" ,calories_burned, "calories.")
Which code segments should you use for line 01 and line 04? Each correct answer
presents part of the solution. Choose two.
Question 40
lOM oAR c P S D | 982 04 78
You create the following code. Line numbers are included for reference only.
For each of the following statements, select Yes if the statement is true.
OtherWise, select No.
Answer Area
A. Yes
B. No
A. Yes
B. No
lOM oAR c P S D | 982 04 78
A. Yes
B. No
Question 1
You are creating a program that accepts user input. The program must cast the
input into an integer. You must properly hand e the error if the code canru.t cast
the input to an integer.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
while True:
1…............
break
lOM oAR c P S D | 982 04 78
2 ...............valueError:
Q-section 1
A. Try:
B. Else:
C. except:
D. Raise:
E. Finally:
Q -section 2
A. Try
B. Else
C. Except
D. Raise
E. Finally
Question 2
Relecloud Virtual Learning asks you to debug some code that is causing problems
with their payroll. They ask you to find the source of the payroll errors. The
following variables have been declared:
Which code should you use to fix the errors? To answer, select the appropriate
code segments in the answer area.
Answer Area
for index in range 1................
count +=1
sum += employee_pay[index]
average = 2..............
print("The total payroll is:", sum )
Q -section 1
E. (size(employee_pay)):
F. (size(employee_pay)-1):
G. (len(employee_pay)+1):
H. (len(employee_pay)):
Q -section 2
D. sum/count
E. sum**count
F. sum*count
Question 3
lOM oAR c P S D | 982 04 78
This question requires that you evaluate the underlined text to determine if it is
correct.
You write the following code:
import sys
try:
file_in = open("in.txt",'r')
file_out = open("out.txt",'w+')
except IOError:
print('cannot open',file_name)
else:
i=l
for line in file_in:
print(line.rstrip())
file_out.write("line " + str(i) + ":" + line)
i = i+ 1
file_in.close()
file_out.close()
The out.txt file does not exist You run the code. The code will execute without
error.
Review the underlined text. If it makes the statement correct, select “No change is
needed.”select the answer choice that makes the statement correct.
Answer Area
I. No change is needed.
J. The code runs, but generate a logic error.
K. The code will generate a runtime error.
L. The code will generate a syntax error
Question 4
Tailspin Toys uses python to control its new toy Happy Clown. The program has
errors that cause the clown to run around in an infinite circle,
lOM oAR c P S D | 982 04 78
You have been hired to help debug the following Happy Clown code. Line numbers
are included for reference only.
import math
#default motion for happy clown
power = True
move = 0
while(power):
if move ==0:
turnValue = math.pi/move
move+=5
else:
turnValue =0
move = 0
Question 5
You are writing a function that increments the player score in a game.
The function has the following requirements:
• If no value is specified for points, then points start at one
• If bonus IS True, then points must be doubled
You write the following code. Line numbers are included for reference only.
02 if bonus == True:
03 points = points * 204
score = score + points
05 return score
06 points = 5
07 score = 10
08 new_score = increment_score(score, True, points)
For each of the following statements, select Yes if the statement is true.
Otherwise, select No.
Note: Each correct selection is worth one point.
Answer Area
To meet the requirements, line 01 must be changed to the following:
def increment_score(score, bonus, points = 1):
A. yes
B. No
Once any parameter is defined with a default value, any parameters to the right
must also be defined with default values.
A. yes
B. No
If the function is called with only two parameters, the value of the third parameter
will be None.
A. yes
B. No
lOM oAR c P S D | 982 04 78
Line 03 will also modify the value of the variable points declared at line
A. Yes
B. No
Question 6
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
1.............................. 2.................................
current+=value
3..............................
lOM oAR c P S D | 982 04 78
Q-section 1
G. update_score
H. def update_score
I. return update_score
Q-section 2
G. (current,value):
H. ():
I. (current,value)
C. D.()
Question 7
You create the following code. Line numbers are included for reference only.
For each of the following statements, select Yes if the statement is true.
OtherWise, select No.
Answer Area
C. Yes
D. No
C. Yes
D. No
C. Yes
D. No
Question 8
Answer Area
A. ' Returns the current balance of the bank account
lOM oAR c P S D | 982 04 78
def get_balance():
return balance
B. def get_balance():
#Returns the current balance of the bank account
return balance
C. def get_balance():
return balance
def get_balance():
return balance
Question 9
You are writing a function to read a data file and print the results as a formatted
table.
The data file contains information about fruit. Each record contains the name of
the fruit, the weight, and the price.
You need to print the data so that it looks like the following sample:
You write the following code. Line numbers included are for reference only.
01 def print_table(file):
02 data - open(file,'r')
03 for record in data:
04 fields = record.split(",")
How should you complete line 05? To answer, drag the appropriate code segments
to the correct location. Each code segment may be used once, more than once, or
not at all. You may need to drag the split bar between panes or scroll to view
content.
Answer Area
Q-section 1
H. print("
I. {10:0}
J. {5:1f}
K. {7:2f}
L. {2:7.2f}
M. {1:5.1f}
N. {0:10}
Q-section 2
lOM oAR c P S D | 982 04 78
H. print("
I. {10:0}
J. {5:1f}
K. {7:2f}
L. {2:7.2f}
M. {1:5.1f}
N. {0:10}
Q-section 3
H. print("
I. {10:0}
J. {5:1f}
K. {7:2f}
L. {2:7.2f}
M. {1:5.1f}
N. {0:10}
Q-section 4
H. print("
I. {10:0}
J. {5:1f}
K. {7:2f}
L. {2:7.2f}
M. {1:5.1f}
N. {0:10}
Question 10
you are creating an ecommerce script that accepts Input from the user and
outputs the data in a comma delimited format,
Which three code should you use? Each correct answer presents a complete
solution.Choose three
A. Print(“{0},{1}”.format(item,sales))
B. Print(‘ “%s” ,%s’ % (item, sales))
C. Print(item + ‘ , ‘ +sales)
D. Print(‘ “ ‘ + item + ‘ “, ‘ +sales)
E. Print(‘”{0}” ,{1}’ .format(item, sales))
Question 11
You are writing a Python program to automate inventory. Your first task is to read
a file of inventory transactions. The file contains sales from the previous day,
including the item id, price, and quantity.
lOM oAR c P S D | 982 04 78
10, 200, 5
20, 100, 1
eof =False
line = inventory.readline()
.................
.................:
print(line)
else:
eof=True
inventory.close()
which code should you write for line 05 and line 06?
E. 05 if line != ’\n’:
06 if line ! =””:
F. 05 if line !=’\n’:
06 if line ! =None:
G. 05 if line ! = ‘ ‘:
06 if line ! = “”:
H. 05 if line != ‘ ‘:
06 if line != “\ns
Question 12
import datetime
d = datetime.datetime(2017, 4, 7)
print('{:%B-%d-%y}' .format(d))
lOM oAR c P S D | 982 04 78
num=1234567.890
print({:,.4f)' .format(num))
You run the program.
Answer Area
A. Apr--07--2017
1,234,567.8900
Press any key to continue..
B. April--07--17
1.234,567.8900
Press any key to continue...
C. April--07--17
1234567.89
Press any key to continue...
D. 2017--ApriI--07
1,234,567.890
Question 13
Northwind Electric Cars needs help updating their file system using Python code.
You must create a simple file manipulation program that performs the following
actions:
How should you complete the code? To answer. select the appropriate code
segments in the answer area.
Answer Area
import os
if 1...............
file =open('myFile.txt')
2...............
file.close()
file = 3............
Q-section 1
A. Isfile(“myFile.txt”):
B. Os.exit(‘myFile.txt’):
C. Os.find(‘myFile.txt’):
D. Os.path.isfile(‘myFile.txt’):
Q-section 2
A. Output(‘myFile.txt’)
B. Print(file.get(‘myFile.txt’))
C. Print(file.read())
D. Print(‘myFile.txt’)
Q-section 3
A. Open(‘myFile.txt’, ‘a’)
lOM oAR c P S D | 982 04 78
B. Open(‘myFile.txt’, ‘a+’)
C. Open(‘myFile.txt’, ‘w’)
D. Open(‘myFile.txt’, ‘w+’)
Q-section 4
A. append
B. file.add
C. file.write
D. write
Question 14
Tailspin Toys is building a basketball court for its employees to improve company
morale.
You are creating a Python program that employees can use to keep track of their
average score.
The program must allow users to enter their name and current scores. The
program will output the user name and the users average score. The output must
meet the following requirements:
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
NOTE: Each correct selection is worth one point.
lOM oAR c P S D | 982 04 78
Answer Area
score =0
count =0
Sum = 0
while(score !=-1):
score =int(input("Enter your scores:(-1 to end)"))
if score == -1:
break
Sum+=score
count +=1
average_score =Sum/count
Q-section 1
I. %-20i
J. %-20d
K. %-20f
L. %-20s
Q-section 2
I. %1.4s
J. %4.1f
lOM oAR c P S D | 982 04 78
K. %4.1S
L. %1.4f
Question 15
You write a function that reads a data file and prints each line of the file. You write
the following code. Line numbers are included for reference only.
01 def read_file(file):
02 line= None
03 if os.path.isfile(file):
04 data = open(file,'r')
05 for line in data:
06 print(line)
When you run the program, you receive an error on line 03.
Answer Area
Question 16
lOM oAR c P S D | 982 04 78
Which two code segments will meet the requirements? Each correct answer
presents a complete solution. Choose two.
Answer Area
A. from random import randrange
print(randint(0, 20)*5)
print(randint(1, 20)*5)
Question 17
lOM oAR c P S D | 982 04 78
You need to write code that generates a random float with a minimum value of
0.0 and a maximum value of 1.0. Which statement should you use?
Answer Area
A. random.randrange(0.0, 1.0)
B. random.randrange()
C. random.random()
D. random.randint(0, 1)
Question 18
Answer Area
numList =[1,2,3,4,5]
alphaList=["a","b","c","d","e"]
1................................
2....................................
Q-section 1
B. if numList==alphaList:
lOM oAR c P S D | 982 04 78
D. B if numList==alphaList
E. else:
F. else
Q-section 2
A. if numList==alphaList:
B. if numList==alphaList
C. else:
D. else
Question 19
You are creating a function to calculate admission fees by using Python. Admission
fees are calculated based on the following rules:
Answer Area
admission_fee(age, school):
rate =0
1.................................
rate =10
lOM oAR c P S D | 982 04 78
2....................................
3 ....................................
rate =20
Q-section 1
Q-section 2
Q-section 3
F. if age <=17:
Question 20
lOM oAR c P S D | 982 04 78
Adventure Works Cycles sales are so exceptional that they decide to give a bonus
to all employees who do not make more than $150,000. The following formula
applies to each employee based on their base salary and a flat bonus:
You need to complete the code that applies an increase to each eligible
employee’s salary.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
salary_list = [150000,340000,230000,500000,100000,120000,90000]
1...................................
2............................................
lOM oAR c P S D | 982 04 78
Q-section 1
Q-section 2
E. exit()
F. continue
G. break
H. end
Question 21
You are creating a Python program that will let a user guess a number from 1 to
10. The user is allowed up to three guesses.
You write the following code. Line numbers are included for reference only.
11 else:
12 print ("Guess is just right!”)
The program must allow three guesses. If the user guesses the correct number,
the program must stop asking for guesses.
How should you complete lines 05, 13, and 14? To answer, drag the appropriate
code segments to the correct locations. Each code segment may be used once,
more than once, or not at all. You may need to drag the split bar between panes
or scroll to view content.
Answer Area
B. break F pass
D. chance = 2
B. break F pass
D. chance = 2
B. break F pass
D. chance = 2
Question 22
You are writing a function in Python that must meet the following requirements:
In which order should you arrange the code segments to develop the solution? To
answer, move all code segments from the list of code segments to the answer
area and arrange them in the correct order.
Answer Area
A - for i in range(len(items)):
B - if items[i]==term:
print("{0} was found in the
list.".format(term))
lOM oAR c P S D | 982 04 78
C - break
D - def search(items,term):
E -
else:
print("{0} was not found in the list."
.format(term))
E. D,A,B,C,E
F. D,B,A,C,E
G. B,D,A,C,E
H. D,A,B,E,C
Question 23
You are writing a Python program to ask the user to enter a number and
determine if the number is 1 digit 2 digits, or more than 2 digits long.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
digits = "1"
2......................................................
digits= 2
.3...................................................
digits= ">2"
Q –section 1
C. if num > - 10 and num < 10:
D. lif num> - 100 and num < 100:
Q-section 2
Q-section 3
C. else:
D. elif:
Question 24
lOM oAR c P S D | 982 04 78
Wingtip Toys is creating an interactive Times Table Helper program intended for
elementary school children.
You need to complete a function that computes and displays all multiplication
table combinations from 2 to 12.
How should you complete the code? To answer, select the appropriate code
segments in the answec area,
Answer Area
def times_tables():
print(row*col,end=" ")
print()
#main
times_tables()
Q-section 1
Q-section 2
Question 25
You are writing a Python program. The program collects customer data and stores
it in a database.
Match the data type to the code segment. To answer, drag the appropriate data
type from the column on the left to its code segment on the right. Each data type
may be used once, more than once, or not at all.
Answer Area
Q1. age =2
E. bool
F. float
G. int
H. str
lOM oAR c P S D | 982 04 78
Q2. minor=False
F. age =2
G. bool
H. float
I. int
J. str
F. age =2
G. bool
H. float
I. int
J. str
Question 26
The studio wants to encourage youth and seniors to sign up. Minors and seniors
must receive a 10% discount.
You write the following code. Line numbers are included for reference only.
Answer Area
Question 27
You create the following code. Line numbers are included for reference only.
For each of the following statements, select Yes if the statement is true.
Otherwise, select No.
Answer Area
Q1. The print statement at line 04 will only print if the two numbers are equal in
value.
C. Yes
D. NO
Q2. The print statement at line 06 will only print if num1 is less than num2.
C. Yes
D. NO
Q3. The print statement at line 08 will only print if num1 is greater than num2.
C. Yes
D. NO
C. Yes
D. NO
lOM oAR c P S D | 982 04 78
Question 28
A list named colors contains 200 colors. You need to slice the list to display every
other color starting with the second color.
Answer Area
E. colors[1::2]
F. colors[1:2]
G. colors[2:2]
H. colors[::2]
Question 29
You need to ensure that you are using the correct comparison operators.
Evaluate each expression and indicate the correct result. To answer, drag the
appropriate result from the column on the left to its expression on the right. Each
result may be used once, more than once, or not at all.
Answer Area
lOM oAR c P S D | 982 04 78
1) . 0 or 5
E. True
F. False
G. 5
H. None
2). bool(0)
E. True
F. False
G. 5
H. None
E. True
F. False
G. 5
H. None
E. True
F. False
G. 5
H. None
Question 30
x=4
while x >= 1:
lOM oAR c P S D | 982 04 78
if x % 4 == 0:
print ("party")
elif x - 2 < 0:
print("cake")
elif x/3 == 0:
print("greeting")
else:
print("birthday")
x=x-1
Answer Area
A. birthday
party
greeting
cake
B. party
greeting
birthday
cake
c. birthday
greeting
party
cake
D. party
birthday
birthday
cake
Question 31
lOM oAR c P S D | 982 04 78
You are writing a program that calculates a user’s year of birth. The program asks
users for their age and the current year, then outputs the users year of birth, You
write the following code. Line numbers are included for reference only.
You need to ensure that the program uses the appropriate data types.
What data types are used? Use the drop-down menus to select the answer choice
that answers each question based on the information presented in the code
segment.
Answer Area
E. int
F. str
G. float
H. bool
E. int
F. str
G. float
H. bool
lOM oAR c P S D | 982 04 78
E. int
F. str
G. float
H. bool
Question 32
alph = “abcdefghijklmnopqrstuvwxyz”
Match the result to the slicing operation. To answer, drag the appropriate result
from the column on the left to its slicing operation on the right. Each result may
be used once, more than once, or not at all.
Answer Area
alph[3:15]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
lOM oAR c P S D | 982 04 78
alph[3:15:3]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
alph[3:15:-3]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
alph [15:3:-3]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
lOM oAR c P S D | 982 04 78
alph[15:3]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
alph[::-3]
I. zwtqnkheb
J. pmjg
K. defghijklmno
L. ponmlkjihgfe
M. defghijklmnop
N. dgjm
O. olif
P. ""
Question 33
a='Configl'
print(a)
b=a
a + = Config2
lOM oAR c P S D | 982 04 78
print(a)
print(b)
Use the drop-down menus to select the answer choice that answers each
question based on the information presented in the code segment.
Answer Area
Q1. What is displayed after the first print?
D. A.Config1
E. Config1Config2
F. C.Config2
D. A.Config1
E. Config1Config2
F. C.Config2
D. A.Config1
E. Config1Config2
Question 34
list_ 1 = [1, 2]
list_2 = [3, 4]
list_3 = list_1 + list_2
list_4 = list_3*3
print(list_4)
Answer Area
E. [[1,2], [3,4],[1,2],[3,4],[1,2],[3,4]]
F. [[1,2,3,4], [1,2,3,4],[1,2,3,4]]
G. [3,6,9,12]
H. [1,2,3,4,1,2,3,4,1,2,3,4]
Question 35
numList = [0,1,2,3,4]
print(5 in numList)
Answer Area
E. 4
F. False
G. True
H. 5
Question 36
You are writing a function that returns the data type of the value that Is passed in.
You write the following code. Line numbers are included for reference only.
01 def checkType(value):
lOM oAR c P S D | 982 04 78
02 dataType = type(value)
03 return dataType
04 print(checkType(True))
05 print(checkType(1.0))
06 print (checkType(1))
07 print(checkType("True"))
Use the drop-down menus to select the answer choice that answers each
question based on the information presented in the code segment
Answer Area
Question 37
You have the following code. line numbers are included for reference only.
01 def main(a,b,c,d):
02 value = a+b*c-d
03 return value
Use the drop-down menus to select the answer choice that answers each
question based on the information presented in the code segment.
Answer Area
D. a+b
E. b*c
F. c-d
C. addition
lOM oAR c P S D | 982 04 78
D. Subtraction
D. (a+b)*(c-d)
E. (a+(b*c))-d
F. a+((b*c)-d)
Question 38
Woodgrove Bank must generate a report that shows the average balance for all
customers each day. The report must truncate the decimal portion of the balance.
Which two code segments should you use? Each correct answer presents a
complete solution. Choose two.
Answer Area
E. average_ba1ance = total_deposits**number_of_customers
F. average_balance = int(total_deposits/number_of_customers)
G. average_balance = total_deposits//number_of_customers
H. average_balance = float(total_deposits//number_of_customers)
Question 39
You need to ensure that a denominator and numerator are passed to the function
and that the denominator is not zero.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
1.......................
2........................
else:
1)
E. if numerator is None or denominator is None:
F. if numerator is None and denometor is None:
G. if numerator = None or denominator =None
H. if numerator = None and denominator = None:
lOM oAR c P S D | 982 04 78
2)
Question 40
You need to write a Python function that outputs the characters in a name in the
correct order.
How should you complete the code? To answer, select the appropriate code
segments in the answer area.
Answer Area
forward_name += 2.............................
return forward_name
Q-section 1
E. backwards_name:
F. len(backwards_name):
G. range(0,len(backwards_name)-1):
H. range(len(backwards_name)-1,-1,-1):
Q-section 2
E. backwards_name[index-1]
F. backwards_name[len(forward_name)-1]
G. backwards_name[len(backward_name)-len(forward_name)]
H. backwards_name[index]