Test 2
1. Create a solution that accepts three
times_traveledA =
integer inputs representing the
int(input()) times_traveledB
number of times an employee
= int(input())
travels to a job site. Output the times_traveledC =
int(input())
total distance traveled to two decimal places employeeA =
15.62 #miles given the following miles per employee com-
employeeB = 41.85 #miles mute to the job site. Output the
total distance employeeC = 32.67 #miles
traveled to two decimal places given the distance_traveledA =
fol- lowing miles per employee times_traveledA * employeeA
commute to the job site: distance_traveledB =
Employee A: 15.62 times_traveledB * employeeB
miles Employee B: distance_traveledC =
41.85 miles Employee times_traveledC * employeeC
C: 32.67 miles total_miles_traveled =
distance_travele- dA +
distance_traveledB + distance_trav-
eledC
print('Distance: {:.2f}
miles'.format(to-
tal_miles_traveled))
2. Create a solution that accepts an input
iden- tifying the name of a text file, for file_name = input()
example, "WordTextFile1.txt". Each with open(file_name, 'r') as f:
text file contains three rows with one word1 = str(f.readline()).strip()
word per row. Using the open() word2 = str(f.readline()).strip()
function and write() and read() meth- word3 = str(f.readline()).strip()
ods, interact with the input text file to
write a new sentence string composed f = open(file_name, 'r')
of the three
existing words to the end of the file contents lines = f.read().splitlines()
1/
15
, WGU D335 Practice
Test 2
on a new line. Output the new file lines = ' '.join(lines)
contents. f.close()
print(f'{word1}\n{word2}\n{word3
n{lines
3. Create a solution that accepts an ounces_per_pound = 16
integer input representing any pounds_per_ton = 2000
number of ounces.
2/
15