WGU D335 Practice Test 2 With Questions And 100% SURE ANSWERS
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 total times_traveledC = int(input())
distance traveled to two decimal places given employeeA = 15.62 #miles
the following miles per employee commute to employeeB = 41.85 #miles
the job site. Output the total distance traveled to employeeC = 32.67 #miles
two decimal places given the following miles per distance_traveledA = times_traveledA * employeeA
employee commute to the job site: distance_traveledB = times_traveledB * employeeB
Employee A: 15.62 miles distance_traveledC = times_traveledC * employeeC
Employee B: 41.85 miles total_miles_traveled = distance_traveledA + distance_traveledB + distance_traveledC
Employee C: 32.67 miles print('Distance: {:.2f} miles'.format(total_miles_traveled))
file_name = input()
Create a solution that accepts an input with open(file_name, 'r') as f:
identifying the name of a text file, for example, word1 = str(f.readline()).strip()
"WordTextFile1.txt". Each text file contains three word2 = str(f.readline()).strip()
rows with one word per row. Using the open() word3 = str(f.readline()).strip()
function and write() and read() methods, interact
with the input text file to write a new sentence f = open(file_name, 'r')
string composed of the three existing words to lines = f.read().splitlines()
the end of the file contents on a new line. Output lines = ' '.join(lines)
WGU
the new file contents. D335 Practice Test f.close()
2
print(f'{word1}\n{word2}\n{word3}\n{lines}')
1/6
, 10/16/24, 6:21 AM
ounces_per_pound = 16
pounds_per_ton = 2000
Create a solution that accepts an integer input number_ounces = int(input())
representing any number of ounces. Output the tons = number_ounces // (ounces_per_pound * pounds_per_ton)
converted total number of tons, pounds, and remaining_ounces = number_ounces % (ounces_per_pound * pounds_per_ton)
remaining ounces based on the input ounces pounds = remaining_ounces // ounces_per_pound
value. There are 16 ounces in a pound and 2,000 remaining_ounces = remaining_ounces % ounces_per_pound
pounds in a ton. 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 example, input1 = input()
"input1.csv". Each file contains two rows of with open(input1, "r") as f:
comma-separated values. Import the built-in data = [row for row in csv.reader(f)]
module csv and use its open() function and for row in data:
reader() method to create a dictionary of even = [row[i].strip() for i in range(0, len(row), 2)]
key:value pairs for each row of comma- odd = [row[i].strip() for i in range(1, len(row), 2)]
separated values in the specified file. Output the pair = dict(zip(even, odd))
file contents as two dictionaries. print(pair)
Create a solution that accepts an integer input index_value = int(input())
representing the index value for any any of the name = various_data_types[index_value]
five elements in the following list: data_type = type(name).__name__
various_data_types = [516, 112.49, True, "meow", print(f"Element {index_value}: {data_type}")
("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
2/6
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Queenstin. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $11.49. You're not tied to anything after your purchase.