CSc 110 - Amayzeon

shopping

As I’m sure you’re all aware, much of the shopping that we do can be done online! Probably the most obvious example of this is amazon.com, but many regular retail stores also have the option for shopping online, tracking purchases, returning items, and more through their apps or websites. In this programming assignment, you are tasked with implementing a shopping system for a small startup named “Amayzeon” that is trying to compete with Amazon. As I’m sure you’ll be able to see, “Amayzeon” (Amazing + Amazon) will end up having far less features than Amazon itself, but maybe, just maybe, it will be able to take some of Amazon’s market share for online retail. This assignment exercises file reading, use of dictionaries and tuples, understanding of mutability, and the webbrowser python module.

Program Structure

For this PA, we will be providing some “starter” code. This code will include a main function (already partially implemented), and a bunch of function definitions, which you will need to implement! Thus, in this PA, you do not have to build the program completely from scratch. Click the link below to download the starter code:

amayzeon.py

You can choose to either download the starter code and build off of that (recommended) or build the entire thing from scratch (not recommended, unless you want to practise you code-organization skills).

Program behavior

amayzeon

This program will behave much like some of the in-class (or in-video) examples we’ve done. The program will continually ask for commands from the user, including:

An example of this program being run and interacted with is shown to the right. There will be a separate function corresponding to most of these actions, which you will have to implement.

Functions to Implement

There are a number of functions which you should implement to get the program working properly. Below, I provide a description of what each function should do. It is up to you to implement them, and then test that they are working properly. I recommend you implement them in the order that they are described in the specification. There will also be a few parts of main that you should implement, and you can implement these as you go about implementing the other functions.

get_content

The purpose of this function is to read in the contents of an inventory list. This function should prompt the user Enter info file name: ", for a file to read in.

The file contains an inventory of all the items Amayzeon currently has available. These items are listed one per line, and each line contains three pieces of information: The name of the item, price, and the Amazon ID (so that the user can view the product on the competitors site, more on that later :). Each of these three components are separated by a single space. You may assume that any multi-word items (such as “xbox one”) will have dashes or underscores in-between instead of spaces. Shown below is an example file:

bedframe 150 B071JGCBH8
box 5 B07JH5Q1JF
calculator 40 B003822IRA
playstation 299 B01LOP8EZC

You must store this information into the inventory dictionary, which is already defined in the main function. The structure of the dictionary should have strings (product name) as the key, mapping to a value (a tuple) containing the price as the first element and the Amazon ID as the second element. The function should return this dictionary

The purpose of this function is to print the Amazon inventory. This function should take in one parameter, the inventory dictionary, with the format as described earlier in this spec. It should then print out the message These are items in inventory: and then list every item in the format item_name - quant. You should not include the ID at this point.

add_to_wallet

The purpose of this function is to simulate adding money to the users wallet. This is the money that can be used to purchase item on Amayzeon. This function should take in two parameters. The first is the users current wallet balance, and the second is the amount to add. The wallet will have a limit of $10,000, therefore before adding you need to check whether or not the limit is exceeded.

If it does, print out Wallet can not exceed $10000. Current wallet $curr_money, and return 0 symbolizing no money was added. If money can be added, print out $money has been added. and return the amount being added.

buy_item

The purpose of this function is to simulate buying an item from Amayzeon. You need to look for an existing item and if you have enough money you can buy it.

This function should take three parameters. The user’s balance, the inventory dictionary, the user’s belongings, and the name of the item to purchase.

If the item does not exist, return 0 and print a message Item does not exist. If the cost of the item is greater than the current money in wallet, return 0 and print a message Sorry, you don't have enough money in your wallet. Otherwise, add item to bought_items dictionary if it doesn’t exist and add 1. Then return the cost of the item.

The purpose of this function is to print out a summary of the current state of the users purchases.

This function takes in two parameters: The current amount of money in the users wallet, and the items that have been bought, in dictionary form.

It should first print the message You have $MONEY in your wallet. If there are no items in bought_items, print the message No items have been purchased. Otherwise it should print out the message You have purchased these items: and then list every item in the format item_name - quantity.

return_item

The purpose of this function is to simulate returning items to Amayzeon. If you have the item, you may be allowed to return said item.

This function should take two parameters, the inventory dictionary and the belongings dictionary.

If the item has not been bought, you should print the message Item has not been bought. and return. Otherwise you should remove 1 from the item if more than one has been bought or remove from the belongings dictionary if only one has been bought. Once item has been returned, print the message Item has been returned.

view_item_on_web

The purpose of this function is to view the item on Amayzeon’s competitor’s (Amazon’s) website. The function should take two parameters, the first being the inventory dictionary, and the second being the name of the item to view. This function is where those Amazon IDs come into play. On Amazon every item has a unique ID, which you can append onto an amazon URL to go directly to that item in a web browser.

For example, the Amazon ID for a playstation 4 is B01LOP8EZC. If you open up a web browser, type https://www.amazon.com/dp/, and then concatenate the ID on the end, it will take you to that amazon page! In this function, you should get the ID associated with the item name, construct the amazon URL (string), and then open it up using the webbrowser module. (The webbrowser module was covered in the slides). An example of the user asking to view a playstation is shown below:

shopping

Complete Examples

items1.txt

Enter info file name:
items1.txt

------ Welcome to Amayzeon! ------
What would you like to do?
inventory
These are items in inventory:
bedframe - $150
box - $5
calculator - $40
playstation - $299
What would you like to do?
buy calculator
Item bought.
What would you like to do?
buy playstation
Sorry, you don't have enough money in your wallet.
What would you like to do?
return calculator
Item has been returned.
What would you like to do?
exit

items2.txt

Enter info file name:
items2.txt

------ Welcome to Amayzeon! ------
What would you like to do?
inventory
These are items in inventory:
basketball - $50
candy-bar - $5
chair - $100
Music-player - $240
pocket-knife - $60
shampoo - $3
toilet - $320
What would you like to do?
add 1000
$1000 has been added.
What would you like to do?
buy chair
Item bought.
What would you like to do?
buy toilet
Item bought.
What would you like to do?
buy candy-bar
Item bought.
What would you like to do?
belongings
You have $675 in your wallet.
You have purchased these items:
chair - 1
toilet - 1
candy-bar - 1
What would you like to do?
return toilet
Item has been returned.
What would you like to do?
belongings
You have $995 in your wallet.
You have purchased these items:
chair - 1
candy-bar - 1
What would you like to do?
exit

Restrictions and Requirements

Submission

This assignment is due on Tuesday, April 28th, at 7pm.



Special thanks to Fontaine Coutino for coming up with this assignment idea!