Answered step by step
Verified Expert Solution
Question
1 Approved Answer
During the prove milestone for the previous lesson, you wrote the part of this program that reads and processes two CSV files, one named products.csv
During the prove milestone for the previous lesson, you wrote the part of this program that reads and processes two CSV files, one named products.csv that contains a catalog of products and one named request.csv that contains a customers order. During this prove assignment, you will add code to finish printing a receipt and to handle any exceptions that might occur while your program is running. Specifically, your program must do the following:
Print the store name at the top of the receipt.
Print the list of ordered items.
Sum and print the number of ordered items.
Sum and print the subtotal due.
Compute and print the sales tax amount. Use as the sales tax rate.
Compute and print the total amount due.
Print a thank you message.
Get the current date and time from your computers operating system and print the current date and time.
Include a try block and except blocks to handle FileNotFoundError, PermissionError, and KeyError.
Helpful Documentation
The prove milestone describes the two CSV files that your program must process.
The preparation content for this lesson explains how to handle exceptions.
The datetime.now method from the standard Python datetime module will get the current date and time from your computers operating system. Here is an excerpt from the official documentation for the datetime.now method:
datetime.nowtzNone
Return the current local date and time.
tz is optional, but if it is not None, it must be a tzinfo time zone information object
These two Microsoft videos explain how to use methods from the standard datetime module.
Date data types minutes
Demonstration: Dates minutes
The following Python code imports the datetime class from the datetime module and calls the datetime.now method to get the current date and time from a computers operating system. Then it uses an fstring to format and print the current date and time.
# Import the datetime class from the datetime
# module so that it can be used in this program.
from datetime import datetime
# Call the now method to get the current
# date and time as a datetime object from
# the computer's operating system.
currentdateandtime datetime.now
# Use an fstring to print the current
# day of the week and the current time.
printfcurrentdateandtime:A I:M p
python examplepy
Tuesday : PM
After the computer executes line in the above code, the variable currentdateandtime will hold the current date and time. Within the fstring at line the string sequences that begin with the percent symbol are called format codes. The format codes and their meaning are listed in the official Python datetime reference. As shown in the terminal window above, the previous example code will print the current day of the week and time to the terminal window.
Help from a Tutor
As a BYUIdaho campus or online student you can get help from a tutor to complete your CSE assignments. Each tutor is a current BYUIdaho student employed by BYUIdaho. Meeting with a tutor is free. It will not cost you any money to meet with a tutor. To get help from a tutor, you simply make an appointment and then meet with the tutor. Campus students meet with tutors in the tutoring center. Online students meet with tutors in Zoom. To make an appointment, follow the instructions in the course tutoring guide.
Testing Procedure
Verify that your program works correctly by following each step in this testing procedure:
Run your program and verify that it prints a receipt formatted similarly to the one shown below. Your program must print the current date and time with exactly the same formatting as shown below. Also, verify that your program computes the number of items, subtotal, sales tax, and total as shown below.
python receipt.py
Inkom Emporium
wheat bread: @
cup yogurt: @
oz granola: @
twix candy bar: @
cup yogurt: @
Number of Items:
Subtotal:
Sales Tax:
Total:
Thank you for shopping at the Inkom Emporium.
Wed Nov ::
Verify that the except block to handle KeyError that you added to your program works correctly by doing the following:
Temporarily add the following line to the end of your requests.csv file and then save the file.
R
Run your program again and verify that it prints an error message like the one shown below.
python receipt.py
Error: unknown product ID in the request.csv file
R
Hint: if you wrote an except block in your program to handle KeyError and added R to the requests.csv file and saved the requests.csv file and ran your program but your program isnt raising a KeyError, then look in your program to see if you wrote an if statement before the statement that finds a value in the products dictionary. Look for code similar to this:
if prodnum in productsdict:
prodinfolist productsdictprodnum
If your
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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