WGU D335 PRACTICE TEST 2 (PRACTICE QUESTIONS WITH ANSWERS
FOR PA) EXAM QUESTIONS AND CORRECT ANSWERS PLUS
RATIONALES | GRADED A+ | VERIFIED ANSWERS | BRAND NEW
VERSION!
Question 1
Create a solution that accepts three integer inputs representing the number of times an
employee travels to a job site. Output the total distance traveled to two decimal places given
the following miles per employee commute to the job site:
• Employee A: 15.62 miles
• Employee B: 41.85 miles
• Employee C: 32.67 miles
times_traveledA = int(input())
times_traveledB = int(input())
times_traveledC = int(input())
# Calculate total distance and format the output
# Your code here# Calculate total distance and format the output
# Your code here
Which code snippet correctly completes the solution?
A)
codePython
total_miles_traveled = (times_traveledA * 15.62) + (times_traveledB * 41.85) +
(times_traveledC * 32.67)
print(f'Distance: {total_miles_traveled} miles')
B)
,codePython
total_miles_traveled = (times_traveledA * 15.62) + (times_traveledB * 41.85) +
(times_traveledC * 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
C)
codePython
total_miles_traveled = (times_traveledA + 15.62) + (times_traveledB + 41.85) +
(times_traveledC + 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
```D)
```python
total_miles_traveled = int(times_traveledA * 15.62) + int(times_traveledB * 41.85) +
int(times_traveledC * 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
Correct Answer: B)
Rationale: This option correctly multiplies the number of trips for each employee by their
respective commute distance and then sums the results. It also correctly uses
the .format() method with the :.2f specifier to format the final output to exactly two decimal
places as required.
Question 2
Create a solution that accepts an input identifying the name of a text file. Each text file
contains three rows with one word per row. Using file handling methods, write a new
sentence string composed of the three existing words to the end of the file contents on a new
line. Output the new file contents.
, codePython
file_name = input()
# Your code here to read the words, append the sentence, and print the new content
```**Which code snippet correctly completes the solution?**
A)
```python
with open(file_name, 'r') as f:
words = f.read().splitlines()
sentence = ' '.join(words)
with open(file_name, 'a') as f:
f.write('\n' + sentence)
with open(file_name, 'r') as f:
print(f.read())
B)
codePython
with open(file_name, 'w') as f:
words = f.readlines()
f.write(' '.join(words))
print(open(file_name, 'r').read())
C)
codePython
FOR PA) EXAM QUESTIONS AND CORRECT ANSWERS PLUS
RATIONALES | GRADED A+ | VERIFIED ANSWERS | BRAND NEW
VERSION!
Question 1
Create a solution that accepts three integer inputs representing the number of times an
employee travels to a job site. Output the total distance traveled to two decimal places given
the following miles per employee commute to the job site:
• Employee A: 15.62 miles
• Employee B: 41.85 miles
• Employee C: 32.67 miles
times_traveledA = int(input())
times_traveledB = int(input())
times_traveledC = int(input())
# Calculate total distance and format the output
# Your code here# Calculate total distance and format the output
# Your code here
Which code snippet correctly completes the solution?
A)
codePython
total_miles_traveled = (times_traveledA * 15.62) + (times_traveledB * 41.85) +
(times_traveledC * 32.67)
print(f'Distance: {total_miles_traveled} miles')
B)
,codePython
total_miles_traveled = (times_traveledA * 15.62) + (times_traveledB * 41.85) +
(times_traveledC * 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
C)
codePython
total_miles_traveled = (times_traveledA + 15.62) + (times_traveledB + 41.85) +
(times_traveledC + 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
```D)
```python
total_miles_traveled = int(times_traveledA * 15.62) + int(times_traveledB * 41.85) +
int(times_traveledC * 32.67)
print('Distance: {:.2f} miles'.format(total_miles_traveled))
Correct Answer: B)
Rationale: This option correctly multiplies the number of trips for each employee by their
respective commute distance and then sums the results. It also correctly uses
the .format() method with the :.2f specifier to format the final output to exactly two decimal
places as required.
Question 2
Create a solution that accepts an input identifying the name of a text file. Each text file
contains three rows with one word per row. Using file handling methods, write a new
sentence string composed of the three existing words to the end of the file contents on a new
line. Output the new file contents.
, codePython
file_name = input()
# Your code here to read the words, append the sentence, and print the new content
```**Which code snippet correctly completes the solution?**
A)
```python
with open(file_name, 'r') as f:
words = f.read().splitlines()
sentence = ' '.join(words)
with open(file_name, 'a') as f:
f.write('\n' + sentence)
with open(file_name, 'r') as f:
print(f.read())
B)
codePython
with open(file_name, 'w') as f:
words = f.readlines()
f.write(' '.join(words))
print(open(file_name, 'r').read())
C)
codePython