(OA) practice With complete solution
Newest 2025/26 RATED A+
Create a solution that accepts three integer inputs representing the number of times an employee travels
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
to a job site. Output the total distance traveled to two decimal places given the following miles per
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
employee commute to the job site. Output the total distance traveled to two decimal places given the
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
following miles per employee commute to the job site:
II! II! II! II! II! II! II! II! II!
Employee A: 15.62 miles II! II! II!
Employee B: 41.85 miles II! II! II!
Employee C: 32.67 miles II! II! II!
times_traveledA = int(input()) II! II!
times_traveledB = int(input()) II! II!
times_traveledC = int(input()) II! II!
employeeA = 15.62 #miles II! II! II!
employeeB = 41.85 #miles II! II! II!
employeeC = 32.67 #miles II! II! II!
distance_traveledA = times_traveledA * employeeA II! II! II! II!
distance_traveledB = times_traveledB * employeeB II! II! II! II!
distance_traveledC = times_traveledC * employeeC II! II! II! II!
total_miles_traveled = distance_traveledA + distance_traveledB + distance_traveledC II! II! II! II! II! II!
print('Distance: {:.2f} miles'.format(total_miles_traveled)) II! II!
Create a solution that accepts an input identifying the name of a text file, for example,
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
"WordTextFile1.txt". Each text file contains three rows with one word per row. Using the open() function
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
and write() and read() methods, interact with the input text file to write a new sentence string composed
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
of the three existing words to the end of the file contents on a new line. Output the new file contents.
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
file_name = input() II! II!
with open(file_name, 'r') as f:
II! II! II! II!
word1 = str(f.readline()).strip()
II! II!
word2 = str(f.readline()).strip()
II! II!
word3 = str(f.readline()).strip()
II! II!
f = open(file_name, 'r')
II! II! II!
lines = f.read().splitlines()
II! II!
lines = ' '.join(lines) II! II! II!
f.close()
print(f'{word1}\n{word2}\n{word3}\n{lines}')
, Create a solution that accepts an integer input representing any number of ounces. Output the converted
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
total number of tons, pounds, and remaining ounces based on the input ounces value. There are 16
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
ounces in a pound and 2,000 pounds in a ton.
II! II! II! II! II! II! II! II! II! II!
ounces_per_pound = 16 II! II!
pounds_per_ton = 2000 II! II!
number_ounces = int(input()) II! II!
tons = number_ounces // (ounces_per_pound * pounds_per_ton)
II! II! II! II! II! II!
remaining_ounces = number_ounces % (ounces_per_pound * pounds_per_ton) II! II! II! II! II! II!
pounds = remaining_ounces // ounces_per_pound II! II! II! II!
remaining_ounces = remaining_ounces % ounces_per_pound II! II! II! II!
print('Tons: {}'.format(tons)) II!
print('Pounds: {}'.format(pounds)) II!
print('Ounces: {}'.format(remaining_ounces)) II!
Create a solution that accepts an input identifying the name of a CSV file, for example, "input1.csv". Each
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
file contains two rows of comma-separated values. Import the built-in module csv and use its open()
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
function and reader() method to create a dictionary of key:value pairs for each row of comma-separated
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
values in the specified file. Output the file contents as two dictionaries.
II! II! II! II! II! II! II! II! II! II! II! II!
import csv II!
input1 = input() II! II!
with open(input1, "r") as f:
II! II! II! II!
data = [row for row in csv.reader(f)]
II! II! II! II! II! II!
for row in data:
II! II! II!
even = [row[i].strip() for i in range(0, len(row), 2)]
II! II! II! II! II! II! II! II!
odd = [row[i].strip() for i in range(1, len(row), 2)]
II! II! II! II! II! II! II! II!
pair = dict(zip(even, odd))
II! II! II!
print(pair)
Create a solution that accepts an integer input representing the index value for any any of the five
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
elements in the following list:
II! II! II! II! II!
various_data_types = [516, 112.49, True, "meow", ("Western", "Governors", "University"), {"apple": 1, II! II! II! II! II! II! II! II! II! II!
"pear": 5}]
II! II!
Using the built-in function type() and getting its name by using the .name attribute, output data type (e.g.,
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
int”, “float”, “bool”, “str”) based on the input index value of the list element.
II! II! II! II! II! II! II! II! II! II! II! II! II! II!
index_value = int(input()) II! II!
name = various_data_types[index_value]
II! II!
data_type = type(name).__name__ II! II!
print(f"Element {index_value}: {data_type}") II! II!
Create a solution that accepts an integer input. Import the built-in module math and use its factorial()
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
method to calculate the factorial of the integer input. Output the value of the factorial, as well as a
II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II! II!
Boolean value identifying whether the factorial output is greater than 100.
II! II! II! II! II! II! II! II! II! II! II!