Latihan Soal
Latihan Soal
DRAG DROP -
You are creating a Python program. The program collects customer data and stores it in a
database.
The program handles a wide variety of data.
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 all.
Select and Place:
Answer :
Question 2
You are creating a Python program that shows a congratulation message to employees on
their service anniversary.
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.
You need to complete the program.
Which code should you use at line 03?
Answer : B
Question 3
HOTSPOT -
You are developing a Python application for your company.
You write the following code:
Use the drop-down menus to select the answer choice that answers each question based on
the information presented in the code segment.
Hot Area:
Answer :
Question 4
DRAG DROP -
You are writing a Python program to perform arithmetic operations.
You create the following code:
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 all.
Select and Place:
Answer :
Question 5
DRAG DROP -
You are writing a Python program that evaluates an arithmetic formula.
The formula is described as b equals a multiplied by negative one, then raised to the second
power, where a is the value that will be input and b is the result.
You create the following code segment. Line numbers are included for reference only.
You need to ensure that the result is correct.
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.
NOTE: Each correct selection is worth one point.
Select and Place:
Answer :
Question 6
• A. 3
• B. 13
• C. 15
• D. 69
Answer : C
Question 7
• A. employees [1:-4]
• B. employees [:-5]
• C. employees [1:-5]
• D. employees [0:-4]
• E. employees [0:-5]
Answer : BE
Question 8
HOTSPOT -
You are an intern for ABC electric cars company. 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.
Hot Area:
Answer :
Question 9
You are creating a function that manipulates a number. The function has the following
requirements:
-> A float is passed into the function
-> The function must take the absolute value of the float
-> Any decimal points after the integer must be removed
Which two math functions should you use? Each correct answer is part of the solution.
(Choose two.)
• A. math.fmod(x)
• B. math.frexp(x)
• C. math.floor(x)
• D. math.ceil(x)
• E. math.fabs(x)
Answer : CE
Explanation:
C: math.floor(x) returns the largest integer less than or equal to x.
E: math.fabs(x) returns the absolute value of x.
Incorrect Answers:
A: math.fmod() takes two variables
B: math.frexp(x) returns the mantissa and exponent of x as the pair (m, e). m is a float and e is
an integer
D: math.ceil(x) returns the smallest integer greater than or equal to x
Question 10
You are writing an application that uses the sqrt function. The program must reference the
function using the name squareRoot.
You need to import the function.
Which code segment should you use?
Answer : C
Question 11
You are writing code that generates 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 two.)
• A. random.randint(5, 12)
• B. random.randint(5, 11)
• C. random.randrange(5, 12, 1)
• D. random.randrange(5, 11, 1)
Answer : BC
Question 12
DRAG DROP -
You are writing a function that works with files.
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.
You write the following code:
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.
Select and Place:
Answer :
Question 13
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.
The following shows a sample of data from the file:
Which code should you write for line 05 and line 06?
A.
B.
C.
D.
Answer : A
Question 14
• A. name = input
• B. input("name")
• C. input(name)
• D. name = input()
Answer : B
Question 15
• A. open("local_data", "r")
• B. open("local_data", "r+")
• C. open("local_data", "w+")
• D. open("local_data", "w")
Answer : C
Explanation:
Modes 'r+', 'w+' and 'a+' open the file for updating (reading and writing). Mode 'w+'
truncates the file.
Question 1 ( Topic 1 )
HOTSPOT -
You are writing a Python program to validate employee numbers.
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 if the format is
incorrect.
False -
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Hot Area:
Answer :
Question 2 ( Topic 1 )
HOTSPOT -
You are coding a math utility by using Python.
You are writing a function to compute roots.
The function must meet the following requirements:
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Hot Area:
Answer :
Question 3 ( Topic 1 )
HOTSPOT -
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:
-> Anyone 18 years old or older receives a rating of "A"
-> Anyone 13 or older, but younger than 18, receives a rating of "T"
-> Anyone 12 years old or younger receives a rating of "C"
-> If the age is unknown, the rating is set to "C"
You need to complete the code to meet the requirements.
Hot Area:
Answer :
Question 4 ( Topic 1 )
HOTSPOT -
You are designing a decision structure to convert a student"™s numeric grade to a letter
grade. The program must assign a letter grade as specified in the following table:
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.
Hot Area:
Answer :
Question 5 ( Topic 1 )
You are developing a Python application for an online product distribution company.
You need the program to iterate through a list of products and escape when a target
product ID is found.
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.
Hot Area:
Answer :
Question 6 ( Topic 1 )
DRAG DROP -
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.
NOTE: Each correct selection is worth one point.
Select and Place:
Answer :
Question 7 ( Topic 1 )
DRAG DROP -
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.
Select and Place:
Answer :
Question 8 ( Topic 1 )
HOTSPOT -
You develop a Python application for your company.
You have the following code. Line numbers are included for reference only.
Use the drop-down menus to select the answer choice that answers each question based on
the information presented in the code segment.
Hot Area:
Answer :
Question 9 ( Topic 1 )
The ABC company has hired you as an intern on the coding team that creates e-commerce
applications.
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.
You need to write the code to meet the requirements.
Which code segment should you use?
Answer : B
Question 10 ( Topic 1 )
HOTSPOT -
You create the following program to locate a conference room and display the room name.
Line numbers are included for reference only.
Answer :
Question 11 ( Topic 1 )
HOTSPOT -
During school holidays, you volunteer to explain some basic programming concepts to
younger siblings.
You want to introduce the concept of data types in Python. You create the following three
code segments:
Answer :
Question 12 ( Topic 1 )
DRAG DROP -
Match the data type to the type operations.
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.
Select and Place:
Answer :
Question 13 ( Topic 1 )
HOTSPOT -
The ABC 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 this code? To answer, select the appropriate code segments in the
answer area.
NOTE: Each correct selection is worth one point.
Hot Area:
Answer :
Question 14 ( Topic 1 )
HOTSPOT -
The ABC Video company 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 returned. However,
there are also special rates on Thursdays and Sundays. The fee structure is shown in the
following list:
-> The cost is $1.59 per night.
-> If the DVD is returned after 8 PM, the customer will be charged an extra day.
-> If the video is rented on a Sunday, the customer gets 30% off for as long as they keep the
video.
-> If the video is rented on a Thursday, the customer gets 50% off for as long as they keep
the video.
You need to write code to meet the requirements.
How should you complete the code? To answer, select the appropriate code segments in the
answer area.
Hot Area:
Answer :
Question 15 ( Topic 1 )
DRAG DROP -
The ABC company is converting an existing application to Python. You are creating
documentation that will be used by several interns who are working on the team.
You need to ensure that arithmetic expressions are coded correctly.
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 list of operations to the
answer area and arrange them in the correct order.
Select and Place:
Answer :
Question 21 ( Topic 1 )
• A. 3
• B. 13
• C. 15
• D. 69
Answer : C
Question 22 ( Topic 1 )
• A. employees [1:-4]
• B. employees [:-5]
• C. employees [1:-5]
• D. employees [0:-4]
• E. employees [0:-5]
Answer : BE
Question 23 ( Topic 1 )
HOTSPOT -
You are an intern for ABC electric cars company. 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.
Hot Area:
Answer :
Question 24 ( Topic 1 )
You are creating a function that manipulates a number. The function has the following
requirements:
-> A float is passed into the function
-> The function must take the absolute value of the float
-> Any decimal points after the integer must be removed
Which two math functions should you use? Each correct answer is part of the solution.
(Choose two.)
• A. math.fmod(x)
• B. math.frexp(x)
• C. math.floor(x)
• D. math.ceil(x)
• E. math.fabs(x)
Answer : CE
Question 25 ( Topic 1 )
You are writing an application that uses the sqrt function. The program must reference the
function using the name squareRoot.
You need to import the function.
Which code segment should you use?
Answer : C
You are writing code that generates 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 two.)
• A. random.randint(5, 12)
• B. random.randint(5, 11)
• C. random.randrange(5, 12, 1)
• D. random.randrange(5, 11, 1)
Correct Answer: BC
Question #27Topic 1
DRAG DROP -
You are writing a function that works with files.
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.
You write the following code:
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.
Select and Place:
Correct
Answer:
Question #28Topic 1
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.
The following shows a sample of data from the file:
Which code should you write for line 05 and line 06?
A.
B.
C.
D.
Correct Answer: A
Question #29Topic 1
You develop a Python application for your company.
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.
• A. name = input
• B. input("name")
• C. input(name)
• D. name = input()
Correct Answer: B
Question #30Topic 1
You develop a Python application for your school.
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.
Which code should you use?
• A. open("local_data", "r")
• B. open("local_data", "r+")
• C. open("local_data", "w+")
• D. open("local_data", "w")
Correct Answer: C
Question #31Topic 1
HOTSPOT -
The ABC 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.
You need to complete the code to meet the 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.
Hot Area:
Question #32Topic 1
HOTSPOT -
The ABC company 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 user's average score. The output must meet the following requirements:
✑ The user name must be left-aligned.
✑ If the user name has fewer than 20 characters, additional space must be added to the right.
✑ The average score must have three places to the left of the decimal point and one place to
the right of the decimal (XXX.X).
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.
Hot Area:
Question #33Topic 1
HOTSPOT -
You find errors while evaluating the following code. Line numbers are included for reference
only.
Correct
Answer:
Question #34Topic 1
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.
The code attempts to read the file even if the file does not exist.
You need to correct the code.
Which three lines have indentation problems? Each correct answer presents part of the
solution. (Choose three.)
• A. Line 01
• B. Line 02
• C. Line 03
• D. Line 04
• E. Line 05
• F. Line 06
• G. Line 07
• H. Line 08
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". If
the statement is incorrect, select the answer choice that makes the statement correct.
• A. No change is needed
• B. The code runs, but generates a logic error
• C. The code will generate a runtime error
• D. The code will generate a syntax error
Correct Answer: A
Question #36Topic 1
HOTSPOT -
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:
Correct
Answer:
Question #37Topic 1
HOTSPOT -
You are developing a Python application for an online game.
You need to create a function that meets the following criteria:
✑ The function is named update_score
✑ The function receives the current score and a value
The function adds the value to the current score
Question #38Topic 1
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?
Correct Answer: A
Question #39Topic 1
The ABC 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 create the following Python code. Line numbers are included for reference only.
• 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):
Correct Answer: AF
Question #40Topic 1
HOTSPOT -
You create a function to calculate the power of a number by using Python.
You need to ensure that the function is documented with comments.
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.
Hot Area:
Correct
Answer:
41. Select the outputs that could be generated by the following code:
import random
print(format(random.random(),'1.2f'))
a. 5.65
b. 14.3
c. 0.99
d. 0.2356
e. 0.00