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
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
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images