In this assignment you will read in a text file; use exception handlining; and use lists of tuples.
We often have to parse in and search data sets. This allows us to make decisions and see patterns that are hard to see by just looking at the raw data.
Often when getting data, it will be in several different formats. CSV (Comma Separated Values) files are the most common. However, even though it is called comma-separated, it often uses other delimiters, such as colons (:), semi-colon (;), or even spaces. Another type of delimiter that can be used are tabs, however this can also be considered a TSV (Tab Separated Values) file. Regardless of the extension (letters after the period), the delimiter is the most important.
One other common formatting feature is that the first line of the file normally contains header information and is not parsed (converted from text to programming data structures). Data structures are ways of organizing data in a way that computers can use the data more easily. A list is a data structure. You will need to handle this parsing of data to a data structure in your solution.
In this application, you will read in a tsv file of books on programming and computing with their ISBN number, list of authors and price. This is a great list of books which you should probably read.
You will then allow the user to search across several of the fields and display the matching results. Users will need to be able to search in the title, ISBN, author, or price. For the results table, you will need to report how many results were found and the average price for all in the table.
Example will be provided below.
For this assignment you will create a module and a script which will use the functions in your module.
You will create a list of lists with each field (data element) parsed to the correct data type from the provided text file (books.tsv).
1. Download the provided text file (books.tsv) from Moodle and copy it into the same folder as your module and script you will be creating.
2. Create a script named parse_file.py
3. Create a function named get_books
a. It accepts a string which contains the relative path to the file.
b. The function will then parse the text file by reading in every line and storing all values in a list of tuples.
i. You will need to skip the first line as it is just headers.
ii. Do not forget to convert appropriate field values to the appropriate type.
iii. You need to return the fields as they are in the provided text file.
1. Title, ISBN, Author(s), Price
2. E.g. ['Coders at Work','978-1430219484','Peter Seibel',28.1]
iv. Do not add additional elements to the tuple.
1. Each tuple should only have 4 elements.
2. You are only returning the parsed data from the file.
c. Make sure to use try:except blocks as appropriate.
i. On failure, make sure to return an empty list.
d. Return the list of tuples.
4. Create a function named get_average_price
a. It accepts a list of books as a list..
b. Using the appropriate value for each item in the list, you will need to calculate average price of all books in the list.
c. Return the float value of the average.
i. Do not round the value.
d. Do not handle case if division by zero happens, allow the exception to be raised.
5. Create a function named filter_by_title
a. It accepts a list of books as lists and search string.
b. Using the appropriate value for each item in the list, you will need see if the search string is found in the book title.
i. Hint 1: This might be a good use of the in operator.
ii. Hint 2: Remember it is a good idea convert your text so you can search it case-insensitive (so that case does not matter).
c. Return a new list with a copy of all results that match the search criteria.
i. Do not modify the original list.
6. Create a function named filter_by_isbn
a. It accepts a list of books as lists and search string.
b. Using the appropriate value for each item in the list, you will need see if the search string is found in the ISBN.
i. Hint 1: This might be a good use of the in operator.
c. Return a new list with a copy of all results that match the search criteria.
i. Do not modify the original list.
7. Create a function named filter_by_author
a. It accepts a list of books as lists and search string.
b. Using the appropriate value for each item in the list, you will need see if the search string is found in the author(s) names.
i. Hint 1: This might be a good use of the in operator.
ii. Hint 2: Remember it is a good idea convert your text so you can search it case-insensitive (so that case does not matter).
c. Return a new list with a copy of all results that match the search criteria.
i. Do not modify the original list.
8. Create a function named filter_by_price
a. It accepts a list of books as lists, price to compare against, and a Boolean as to whether to filter by minimum or maximum price.
b. Using the appropriate value for each item in the list, you will need see if the price is within the range.
i. If you are searching by maximum price, return all books which are less than or equal to the price given.
ii. If you are searching by minimum price, return all books which are greater than or equal to the price given.
iii. Hint 1: Your data should already be in the correct data types in your list.
c. Return a new list with a copy of all results that match the search criteria.
i. Do not modify the original list.
1. Create a script named book_search.py
2. Get the full results from the file.
3. Store the tax_rate for the calculating price with tax.
a. We are in Idaho, so use 6% sales tax.
4. Prompt the user for which to search.
a. Hint: a sentinel loop would help here.
b. The options must be the following letters:
i. t – title
ii. i – ISBN
iii. a – author names
iv. x – maximum price
v. n – minimum price
vi. l – list all
5. Validate that the user input a correct value.
a. If the value is not a valid option, prompt the user again.
b. Only continue when you have a valid option.
6. If the user selected anything other than all, prompt the user for the text to search for and then call the appropriate function to get the filtered list.
7. If the user selects ‘all’, then the results will include all of the books.
8. Display the number of results in the list (filtered or unfiltered as appropriate).
9. Using the list, display a table with has the column headers and the following columns:
a. Row number
i. Number of the row, not the original number in the text file.
b. Book Title
i. Title of the book.
c. ISBN
i. ISBN in the format XXX-XXXXXXXXXX
d. Author Names
i. List of authors’ names separated with commas with more than one author.
e. Price (without tax)
i. As US dollars
f. Price (with tax)
i. As US dollars
10. Finally, using the get_average_price function, get and print out the average price for the list printed (not the whole list).
a. Use a try:except block so that if the list has no items and has an error, the score is printed as “ ”
i. Hint: nothing in the list will cause a divide by zero exception.
Start by getting and printing out all results, before you worry about filtering results. Make sure to test all of your functions, one at a time.
Start small and build on a little bit as you go.
As with every other assignment, the functions listed are the minimum requirements. It might be wise to create extra functions to make your coding easier.
1. 5% - Compiles without errors
2. 18% - get_books (type hinting, correct parameters)
a. uses try:except, opens file, reads lines correctly, parses data into tuple, uses correct data types, returns list of tuples, returns empty list on exception
3. 5% - get_average_price (type hinting, correct parameters)
a. returns correct average from lists
4. 10% - filter_by_title (type hinting, correct parameters)
a. iterates each inner list, checks for search text in value, uses correct values, returns new list
5. 9% - filter_by_isbn (type hinting, correct parameters)
a. iterates each inner list, checks for search text in value, uses correct values, returns new list
6. 10% - filter_by_author (type hinting, correct parameters)
a. iterates each inner list, checks for search text in value, uses correct values, returns new list
7. 17% - filter_by_price (type hinting, correct parameters)
a. Max - iterates each inner list, checks for price in value, uses correct values, returns new list of books with a cost less than the price if max price is selected
b. Min - iterates each inner list, checks for price in value, uses correct values, returns new list of books with a cost greater than the price if min price is selected
8. 1% - calls get_books
9. 1% - prompts user for input
10. 2% - loops until correct answer
11. 3% - prompts for search input correctly
12. 3% - calls correct function based on type of search
13. 1% - displays number of results
14. 1% - displays table header from filtered list
15. 5% - displays results in a table
16. 2% - displays average of results in table
17. 2% - uses try:except to handle for average of empty list
18. 10% - Good Coding (compiles, good comments, header block, doc_strings, comments andgood variable names)
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme