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