Problem description: Write a python application to simulate an Amazon online book shopping system, namely “Amazing”. Design solution: The template file contains a list of books sold on Amazing, each item in the list contains the title, publication year, author and the prices. The program will generate an items_dict where each key is the title of the book and the values will be a list of year, author and price information. A customer will be presented with a main menu with 4 different options: display all items, add an item to cart, checkout and exit the program. A customer can buy an item by entering the title of the book. This program implements a dictionary called cart, where each key is the title and the values are the list of year, author and price and We assume one copy is added with each selection. The program keeps repeating by displaying the main menu to user until user hits the quit button. If user hits the checkout option, the program will display all the items in the cart and display the total amount purchased. Implementation: 1. This program will require to use two .py files: utility and application files. utility file contains all the helper functions. The application file contains the main functionality of the program. 2. This program requires to implement two dictionaries: items_dict and cart. items_dict will be populated from the given list of books at the beginning of the program. Each key will be the title and the value will be a list of author, year and price. cart dictionary will be a subset of items_dict that contains all the items user wants to purchase. The structure will be same as items_dict. 3. The application file will contain a main function. main function implements the user menu and calls all the functions from the utility file. Hint: How to import a function from one file to another? 4. Utility file will contain the following function definitions. All these function call will be made from application file. a. build_dict(items): Returns items_dict from items list. items list is provided in the template file. This function is defined in the utility file and will be called from the application file at the beginning of the program. b. checkout(cart): Returns the total amount purchased using the user cart. This function will be called when user chooses to checkout for option 3. cart contains all the books user is purchasing. checkout function will get the price of an item from the cart dictionary and returns the total amount. Hint: price of an item is the last item from the cart’s value list. c. display_all_items(d): Takes any dictionary d and display all the items in the dictionary. This function will be called for menu option 1 and option 3. Hint: How to print a dictionary? d. add_books_to_cart(title, cart, items_dict): Add an item to cart from the items_dict if title exists in the items_dict. For menu option 2, user will provide the title. If title exists that book will be added to the cart. Upon successful addition the function will return True otherwise returns False.       Sample I/O: Welcome to shopping at Amazing! We sell books from American Novelists Please choose from the following options to get information on available books 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 1 Title-Author-Year-Price Animal Farm- George Orwell- 1945- 19.99 The Great Gatsby- Scott Fitzgerald- 1934- 22.99 Jane Eyre- Charlotte Bronte- 1847- 27.99 Anna Karenina- Leo Tolstoy- 1877- 21.99 Sanctuary- William Faulkner- 1931- 30.99 Adventures of Huckleberry Finn- Mark Twain- 1884- 28.99 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 2 Enter the title of the book to add: Animal Farm Animal Farm added to cart 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 2 Enter the title of the book to add: Introduction to Programming Introduction to Programming not found. Returning to main menu... 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 2 Enter the title of the book to add: Jane Eyre Jane Eyre added to cart 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 3 Thanks for shopping You purchased the following items: Title-Author-Year-Price Animal Farm- George Orwell- 1945- 19.99 Jane Eyre- Charlotte Bronte- 1847- 27.99 The total amount is: $ 47.98 1. Display all items 2. Add books to cart 3. Checkout 4. Quit Enter your option: 4 The program is quitting

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 5PP: (Data processing) Write a C++ program that reads the file created in Exercise 4, permits the user to...
icon
Related questions
Question

Problem description: Write a python application to simulate an Amazon online book shopping
system, namely “Amazing”.

Design solution: The template file contains a list of books sold on Amazing, each item in the list
contains the title, publication year, author and the prices. The program will generate an
items_dict where each key is the title of the book and the values will be a list of year, author
and price information. A customer will be presented with a main menu with 4 different options:
display all items, add an item to cart, checkout and exit the program. A customer can buy an
item by entering the title of the book. This program implements a dictionary called cart, where
each key is the title and the values are the list of year, author and price and We assume one
copy is added with each selection. The program keeps repeating by displaying the main menu
to user until user hits the quit button. If user hits the checkout option, the program will display
all the items in the cart and display the total amount purchased.
Implementation:
1. This program will require to use two .py files: utility and application files. utility file
contains all the helper functions. The application file contains the main functionality of
the program.
2. This program requires to implement two dictionaries: items_dict and cart. items_dict
will be populated from the given list of books at the beginning of the program. Each key
will be the title and the value will be a list of author, year and price. cart dictionary will
be a subset of items_dict that contains all the items user wants to purchase. The
structure will be same as items_dict.
3. The application file will contain a main function. main function implements the user
menu and calls all the functions from the utility file. Hint: How to import a function from
one file to another?
4. Utility file will contain the following function definitions. All these function call will be
made from application file.
a. build_dict(items): Returns items_dict from items list. items list is provided in the
template file. This function is defined in the utility file and will be called from the
application file at the beginning of the program.
b. checkout(cart): Returns the total amount purchased using the user cart. This
function will be called when user chooses to checkout for option 3. cart contains
all the books user is purchasing. checkout function will get the price of an item
from the cart dictionary and returns the total amount. Hint: price of an item is
the last item from the cart’s value list.
c. display_all_items(d): Takes any dictionary d and display all the items in the
dictionary. This function will be called for menu option 1 and option 3. Hint: How
to print a dictionary?
d. add_books_to_cart(title, cart, items_dict): Add an item to cart from the
items_dict if title exists in the items_dict. For menu option 2, user will provide
the title. If title exists that book will be added to the cart. Upon successful
addition the function will return True otherwise returns False.

 

 

 

Sample I/O:

Welcome to shopping at Amazing!
We sell books from American Novelists
Please choose from the following options to get information on available books
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 1
Title-Author-Year-Price
Animal Farm- George Orwell- 1945- 19.99
The Great Gatsby- Scott Fitzgerald- 1934- 22.99
Jane Eyre- Charlotte Bronte- 1847- 27.99
Anna Karenina- Leo Tolstoy- 1877- 21.99
Sanctuary- William Faulkner- 1931- 30.99
Adventures of Huckleberry Finn- Mark Twain- 1884- 28.99
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 2
Enter the title of the book to add: Animal Farm
Animal Farm added to cart
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 2
Enter the title of the book to add: Introduction to Programming
Introduction to Programming not found. Returning to main menu...
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 2
Enter the title of the book to add: Jane Eyre
Jane Eyre added to cart
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 3
Thanks for shopping
You purchased the following items:
Title-Author-Year-Price
Animal Farm- George Orwell- 1945- 19.99
Jane Eyre- Charlotte Bronte- 1847- 27.99
The total amount is: $ 47.98
1. Display all items
2. Add books to cart
3. Checkout
4. Quit
Enter your option: 4
The program is quitting

Application file
import firstname_lastname_HA4_utility as u #import a file asu - change the file name
def main():
items = ['Animal Farm, George Orwell, 1945, 19.99', ' The Great Gatsby, Scott Fitzgerald, 1934, 22.99',
"Jane Eyre, Charlotte Bronte, 1847, 27.99', 'Anna Karenina, Leo Tolstoy, 1877, 21.99',
"Sanctuary, William Faulkner, 1931, 30.99', 'Adventures of Huckleberry Finn, Mark Twain, 1884, 28.99']
items_dict = u.build_dict(items) #calls a function from utility file
cart = {} #cart initializaation
print('Welcome to shopping at Amazing!')
print('We sell books from American Novelists\nPlease choose from the following options to get information on available books')
while True:
#print menu
#take user option
#call appropriate function from utility file according to user input.
main()
Transcribed Image Text:Application file import firstname_lastname_HA4_utility as u #import a file asu - change the file name def main(): items = ['Animal Farm, George Orwell, 1945, 19.99', ' The Great Gatsby, Scott Fitzgerald, 1934, 22.99', "Jane Eyre, Charlotte Bronte, 1847, 27.99', 'Anna Karenina, Leo Tolstoy, 1877, 21.99', "Sanctuary, William Faulkner, 1931, 30.99', 'Adventures of Huckleberry Finn, Mark Twain, 1884, 28.99'] items_dict = u.build_dict(items) #calls a function from utility file cart = {} #cart initializaation print('Welcome to shopping at Amazing!') print('We sell books from American Novelists\nPlease choose from the following options to get information on available books') while True: #print menu #take user option #call appropriate function from utility file according to user input. main()
U file
def build_dict(items):
Returns items_dict from items list. "
items_dict = {}
#your code here
return items_dict
def checkout(cart):
" Returns total price from cart dictionary''
total = 0
#your code here
#for each key in cart
#obtain the price from value list
#keep adding to total
#return total
def display_all_items (items_dict):
'" Display a dictionary key and value'
#your code here
def add_books_to_cart(title, cart, items_dict):
''Add an item to cart if title exists. Returns True if added
otherwise returns False''
#your code here
#check if title in the items_dict
#add item to the cart
#return True if added otherwise returns False
Transcribed Image Text:U file def build_dict(items): Returns items_dict from items list. " items_dict = {} #your code here return items_dict def checkout(cart): " Returns total price from cart dictionary'' total = 0 #your code here #for each key in cart #obtain the price from value list #keep adding to total #return total def display_all_items (items_dict): '" Display a dictionary key and value' #your code here def add_books_to_cart(title, cart, items_dict): ''Add an item to cart if title exists. Returns True if added otherwise returns False'' #your code here #check if title in the items_dict #add item to the cart #return True if added otherwise returns False
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr