Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

WGU D 335 Introduction to Programming in Python home Practice Test 2 Latest Update Questions and 100% Verified Correct Answers Guaranteed A+

Rating
-
Sold
-
Pages
9
Grade
A+
Uploaded on
18-06-2025
Written in
2024/2025

WGU D 335 Introduction to Programming in Python home Practice Test 2 Latest Update Questions and 100% Verified Correct Answers Guaranteed A+

Institution
WGU D 335 Introduction To Programming In Python Ho
Course
WGU D 335 Introduction to Programming in Python ho

Content preview

WGU D 335 Introduction to Programming in
Python home Practice Test 2 Latest Update 2025-
2026 Questions and 100% Verified Correct
Answers Guaranteed A+

Create a solution that accepts a string input representing a grocery store item and an
integer input identifying the number of items purchased on a recent visit. The following
dictionary purchase lists available items as the key with the cost per item as the value.

purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery": 2.81, "milk": 4.34}
Additionally,
If fewer than ten items are purchased, the price is the full cost per item.

If between ten and twenty items (inclusive) are purchased, the purchase gets a 5%
discount.
If twenty-one or more items are purchased, the purchase gets a 10% discount.

Output the chosen item and total cost of the purchase to two decimal places.

The solution output should be in the format

item_purchased $total_purchase_cost -CORRECT ANSWER: item_purchased =
input().lower()

num_items = int(input())

if item_purchased in purchase:
total_purchase_cost = purchase[item_purchased]* num_items



if 10 <= num_items <= 20:
total_purchase_cost = total_purchase_cost - (total_purchase_cost*.05)

elif num_items >= 21:

total_purchase_cost = total_purchase_cost - (total_purchase_cost*.10)


print(f"{item_purchased} ${total_purchase_cost:.2f}")

, Create a solution that accepts an input identifying the name of a CSV file, for example,
"input1.csv". Each file contains two rows of comma-separated values. Import the built-in
module csv and use its open() function and reader() method to create a dictionary of
key:value pairs for each row of comma-separated values in the specified file. Output the
file contents as two dictionaries.

The solution output should be in the format
{'key': 'value', 'key': 'value', 'key': 'value'} {'key': 'value', 'key': 'value', 'key': 'value'} -
CORRECT ANSWER: import csv
input1 = input()

with open(input1, "r") as f:

data = csv.reader(f)

for row in data:

even = [row[i].strip() for i in range(0, len(row), 2)]

odd = [row[i].strip() for i in range(1, len(row), 2)]

pair = dict(zip(even, odd))
print(pair)



Create a solution that accepts an input identifying the name of a text file, for example,
"WordTextFile1.txt". Each text file contains three rows with one word per row. Using the
open() function and write() and read() methods, interact with the input text file to 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.

The solution output should be in the format

word1 word2 word3 sentence -CORRECT ANSWER: file_name = input()

with open(file_name, 'r') as f:
word1 = f.readline().strip()

word2 = f.readline().strip()

word3 = f.readline().strip()
sentence = f"{word1} {word2} {word3}"

Written for

Institution
WGU D 335 Introduction to Programming in Python ho
Course
WGU D 335 Introduction to Programming in Python ho

Document information

Uploaded on
June 18, 2025
Number of pages
9
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$20.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Tutordiligent Chamberlain College Of Nursng
Follow You need to be logged in order to follow users or courses
Sold
609
Member since
3 year
Number of followers
219
Documents
8347
Last sold
4 days ago
Tutordiligent

Tutordiligent is a Medical Professional with a Bachelor of Medicine and Bachelor of Surgery (MBBS) from Chamberlain College of Nursing of Health Sciences. His academic journey included internships in Radiology, Cardiology, and Neurosurgery. His contributions to medical research extend to two publications in medical journals, solidifying his position as a promising addition to the field.

3.6

94 reviews

5
35
4
19
3
22
2
3
1
15

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions