Question
Input from CSV file, Dictionary practice You should use the CSV module (documentation) https://docs.python.org/3/library/csv.html to read the contents
Input from CSV file, Dictionary practice
You should use the CSV module (documentation) https://docs.python.org/3/library/csv.html to read the contents of the attached file orders.csv into a dictionary (not a list). The keys of the dictionary should be orderNumber's from the CSV file, and the values should be the deliveryDate's from the CSV file.
The structure of the attached CSV file is:
[orderNumber], [deliveryDate]
Once everything is in the dictionary, iterate through the dictionary using a loop and on each iteration of the loop, output a notification for each order in this format:
"Thank you for using the promo code ”10PCTOFF”. A 10% discount was applied to order #[orderNumber]. Your backpack will be delivered on or before [deliveryDate].
(for each string output as above, orderNumber and deliveryDate should correspond to entries in the dictionary)
Python
Input from CSV file, Dictionary practice
WHAT TO SUBMIT: Your code in this text box below.
I'm unable to upload on here so here is the download link for the CSV file: https://www.dropbox.com/scl/fi/2464umtzog0oblb0a8nlw/orders.csv?rlkey=ja3cock8cbfvgkbgfa721wrwd&dl=0
**Previous code below is either incorrect or doesn't work.The file was in the same directory but still isn't working. Please help me resolve with the correct code. Make to review the code and check for syntax errors, etc and be sure to run the program and provide a screenshot of the output if possible to show that it actually works:
# Create an empty dictionary to store the data
order_data = {
# Read the CSV file and populate the dictionary
with open('orders.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
order_data[row['orderNumber']] = row['deliveryDate']
# Iterate through the dictionary and create the output
for orderNumber, deliveryDate in order_data.items():
promo_message = f"Thank you for using the promo code '10PCTOFF'. A 10% discount was applied to order #{orderNumber. Your backpack will be delivered on or before {deliveryDate."
print(promo_message) a
Step by Step Solution
3.52 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
It appears there are a few issues in your code Let me provide you with the corrected co...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started