Dumps
Dumps
3. You are writing code to generate a random integer with a minimum value of 5 and a maximum value of 11.
Which two functions should you use? Each correct answer presents a complete solution. (Choose 2.)
A. random.randrange (5, 11, 1)
B.random.randint(5, 12)
C. random.randint(5, 11)
D. random.randrange (5, 12, 1)
4. You are developing a Python application for your company.
You need to accept input from the user and print that information to the user's screen.
You start with the following code. Line numbers are included for reference only.
01 print("What is your name?")
02
03 print(name)
6. A 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 achieve the goal? Each correct answer
presents a complete solution. (Choose 2.)
A. average_balance = int(total_deposits/number_of_customers)
B. average_balance = total_deposits**number_of_customers
C. average_balance = total_deposits//number_of_customers
D. average_balance=float(total_deposits//number_of_customers)
11. You develop a Python application for your company. You want to add notes to your code so other team
members will understand it.
What should you do?
A. Place the notes after # on any line.
B. Place the notes within <!-- and --> in any code segment.
C. Place the notes after // on any line.
D. Place the notes within /* and */ in any code segment.
12. Review the following code segment:
product = 2
n = 5
while (n != 0) :
product *= n
print (product)
n -= 1
if n == 3:
break
How many lines of output does the code print?
Enter the number as an integer here: 2
15. You are creating a function that manipulates a number passed into the function as a float value. The
function must perform the following tasks:
17. A bank is migrating their legacy bank transaction code to Python. The bank hires you to document the
migrated code. Which documentation syntax is correct?
Α. // Returns the current balance of the bank account
def get_balance():
return balance
B. Returns the current balance of the bank account
def get_balance():
return balance
C. def get_balance():
# Returns the current balance of the bank account
return balance
D. def get_balance():
/* Returns the current balance of the bank account */
return balance
18. The following function calculates the value of an expression that uses an exponent. Line numbers are
included for reference only.
01 def calc_power (a, b):
02 return a**b
03 base = input("Enter the number for the base: ")
04 exponent = input("Enter the number for the exponent: ")
05 result = calc_power (base, exponent)
06 print("The result is " + result)
For each statement, select True or False.
Note: You will receive partial credit for each correct selection.
Answer Area
The code will generate an error in line 03 and line 04. (True)
The code will generate an error in line 02 and line 05. (True)
The code will correctly output data to the console. (True)
For each statement about the code segment, select True or False.
A file named python.txt is created if it does not exist. (True)
The data in the file will be overwritten. (False)
Other code can open the file after this code runs. (True)
20. You create the following Python function to calculate the power of a number. Line numbers are included
for reference only.
01 # The calc_power function calculates exponents
02 # x is the base
03 # y is the exponent
04 # The value of x raised to the y power is returned
05 def calc_power(x, y):
06 comment = "# Return the value"
07 return x ** y # raise x to the y power
For each statement, select True or False.
Python will not check the syntax of lines 01 through 04. (True)
The pound sign (#) is optional for lines 02 and 03. (True)
The string in line 06 will be interpreted as a comment. (False)
Line 07 contains an inline comment. (True)
22. The following function calculates the value of an expression that uses an exponent. Line numbers are
included for reference only.
01 def calc_power(a, b):
02 return a**b
03 base = input("Enter the number for the base: ")
04 exponent = input("Enter the number for the exponent: ")
05 result calc_power (base, exponent)
06 print("The result is " + result)
25. A bicycle company is creating a program that allows customers to log the number of miles biked. The
program will send messages based on how many miles the customer logs.
You write 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
06 return calories
07 distance = int(input("How many miles did you bike this week? "))
08 burn_rate = 50
09 biker get_name()
10 calories burned calc_calories (distance, burn_rate)
11 print(biker, ", you burned about ", calories_burned, " calories.")
You need to define the two required functions.
Which two code segments should you use for line 01 and line 04? Each correct answer presents part of the
solution. (Choose 2.)
A. 01 def get_name():
B. 01 def get_name(biker):
C. 01 def get_name(name):
D. 04 def calc_calories():
E. 04 def calc_calories(miles, burn_rate):
F. 04 def calc_calories(miles, calories_per_mile):
26. Students are attending an activity night at their school. The following function tells students where to go
for their activities:
def roomAssignment (student, year):
"""Assign rooms to students"""
if year == 1:
print (f" \n{student.title()}, please report to room 115")
elif year == 2:
print(f"\n{student.title()}, please report to room 210")
elif year == 3:
print(f" \n{student.title()}, please report to room 320")
elif year == 4:
print (f"\n{student.title()}, please report to room 405")
elif year == 5:
print(f" \n{student.title()}, please report to room 515")
else:
print (f" \n{student.title()}, please report to room 625")
Which two code segments can be used to call the function? (Choose 2.) Each correct code segment is a
complete solution.
Note: You will receive partial credit for each correct selection.
A. name = input("What is your name?")
grade=0
while grade not in (1,2,3,4,5,6):
grade = int(input("What grade are you in (1-6)?"))
roomAssignment (name, year=grade)
B. name = input("What is your name?")
grade=0
while grade not in (1,2,3,4,5,6):
grade = int(input("What grade are you in (1-6)?"))
roomAssignment (student, year)
C. roomAssignment ("Sherlock Sassafrass",4)
D. roomAssignment (year=6, name="Minnie George")
27.
28. 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.
01 def increment_score (score, bonus, points):
02 if bonus == True:
03 points = points * 2
04 score = score + points
05 return score
06 points = 5
07 score = 10
08 new_score= increment_score (score, True, points)
For each statement, select True or False.
Note: You will receive partial credit for each correct selection.
To meet the requirements, you must change line 01 to: def increment_score (score, bonus, points = 1):
(True)
If you do not change line 01 and the function is called with only two parameters, the value of the third
parameter will be None. (True)
Line 03 will also modify the value of the variable points declared at line 06. (False)
29. View the following program. Line numbers are for reference only.
def petstore (category, species, breed = "none"):
print (f" \nYou have selected an animal from the {category}
category."
if breed == "none":
print("The {category) you selected is a (species}")
else:
print (f"The [category} you selected is a {species}
{breed}")
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.