Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Final Project- Adrian Camano & Ryan Donaldson
- # Import the UUID module to help us with generating a
- # unique transaction ID
- import uuid
- # Generates a transaction ID
- def generate_transaction_id():
- # Casts uuid object to a 128-bit hexadecimal string
- fullUuid = uuid.uuid4().hex
- # Only take the first section of the UUID to make it look more
- # like a real transaction ID
- transactionId = fullUuid[0:7]
- # Returns the transaction ID as an upper case string
- return transactionId.upper()
- # Function that formats either of our inventories to print pretty
- def print_inventory(storage):
- # If our dictionary is not empty, then format
- if bool(storage):
- # Iterate through our inventory to get the ID, title, and price of the item
- for partId, inventory in storage.iteritems():
- for title, price in inventory.iteritems():
- print "%s. %s - $%d" % (partId, title, price)
- else:
- # Print if our dictionary is empty
- print "There is nothing in our inventory or nothing in your shopping cart right now!"
- # Function that ends our program
- def end():
- print "Thank you for shopping with us!"
- pass
- # Stores all of our computer store parts, ID as key, another dictionary as a value
- # with title and price of the item
- parts = {
- 1: {"Logitech Keyboard": 100},
- 2: {"Logitech VX Nano Wireless Mouse": 280},
- 3: {"LG LCD LED Monitor": 650},
- 4: {"Asus SABERTOOTH Z97 Motherboard": 200},
- 5: {"Intel Core i7-5930K CPU": 580},
- 6: {"SAPPHIRE NITRO Radeon R9 390 Graphics Card": 340},
- 7: {"HIS Radeon R9 390 DirectX 12 System Fans": 320},
- 8: {"Thermaltake Core V71 Computer Case": 120},
- 9: {"Seagate Desktop HDD.15 Hard Drive": 130},
- 10: {"Microsoft Windows 10 Home-64bit-OEM": 100}
- }
- # Stores all of the items in our shopping cart
- shopping_cart = {
- }
- print "Welcome!"
- print "\nPlease enter your username and password to begin."
- # Stores our list of users
- allowed_users = ['ADMIN']
- # Stores our list of passwords for each user
- passwords = ['admin']
- # Asks for a username to login with
- username = raw_input("Username: ")
- # Asks for a password to login with
- password = raw_input("Password: ")
- # Controls if the user belongs to allowed_users, checks if a username or password
- # can be found in each of their respective arrays
- if username in allowed_users and password.lower() or password.upper() in passwords:
- print "\nWelcome, Admin!"
- else:
- # End the program if they entered a wrong username or password
- print "\nAccess denied, please try again later!"
- exit()
- # Stores the user's current balance
- money = 1000.00
- # Print amount of money in their balance when they login
- print "Thanks for logging in! You have currently $%s in your account." % money
- # Loops main menu until break
- while True:
- # Print menu selection
- selection = raw_input("""What would you like to do?:
- \t1) Browse Inventory
- \t2) View Shopping Cart
- \t3) Leave
- """)
- if selection == "1":
- # If user chooses to browse inventory, print the inventory and ask if they
- # would like to purchase an item
- while True:
- print "Here is our current inventory:"
- print_inventory(parts)
- selection = int(raw_input("\nWhat would you like to purchase?: "))
- # If the ID of the user input can be found in the array, add it to
- # shopping cart
- if selection in parts:
- # Gets the value based on the ID in the inventory
- inv = parts[selection]
- # Since there's 1 key & value for each value of our inventory
- # it's safe to access the 0th element and assign to a
- # variable for title & price
- title = inv.keys()[0]
- price = inv.values()[0]
- # Add a new element to our dictionary
- shopping_cart[title] = price
- # Tell the user they have added the item to their shopping cart
- print "You have added %s - $%d to your shopping cart." % (title, price)
- continuee = raw_input("\nWould you like to continue shopping?: ")
- # If user wants to continue shopping, repeat this inner while
- # loop. Else, start over and print the main menu again
- if continuee == "Yes":
- continue
- else:
- break
- # If the user wants to view their shopping cart, format the dictionary
- # to be a readable by the user, add each price value to their total
- # price and then ask if they would like to checkout
- elif selection == "2":
- # Stores total price for all items
- total_price = 0
- # If the user has items in their shopping cart, continue
- if bool(shopping_cart):
- # Formats our dictionary to tell the user what's in their shopping cart
- print "Here is what's currently in your shopping cart:"
- i = 0
- for title, price in shopping_cart.iteritems():
- i = i + 1
- print "%s. %s - $%d" % (i, title, price)
- # Adds each price to their total price
- for price in shopping_cart.values():
- total_price += price
- checkout = raw_input("\nWould you like to checkout?: ")
- if checkout == "Yes":
- # If they choose to checkout, generate a transaction ID
- # and add sales tax & S+H to their cost
- transaction_id = generate_transaction_id()
- sales_tax = total_price * 0.07
- with_shipping_handling = total_price + sales_tax + 9.95
- # Print total cost & transaction
- print "\nTotal Cost: $%d" % (total_price)
- print "Total Cost w/ Sales Tax: $%d" % (total_price + sales_tax)
- print "Total Cost w/ Sales Tax & Shipping and Handling: $%d" % (with_shipping_handling)
- print "Transaction ID: %s" % (transaction_id)
- # If they do not have money to purchase all the items, end the
- # program
- if money < with_shipping_handling:
- print "You do not have enough money to purchase all these items!"
- break
- else:
- # Clears all items from the shopping cart
- shopping_cart.clear()
- # Subtract total_price from their money
- money -= with_shipping_handling
- # Print their new balance
- print "Your balance is now: $%d" % (money)
- # If they would like to continue shopping, print the main menu
- # again or else end the program
- continue_shopping = raw_input("\nWould you like to continue shopping?: ")
- if continue_shopping == "Yes":
- continue
- else:
- end()
- break
- # If the user has no items in their shopping cart, go back to the main menu
- else:
- print "You do not have any items in your shopping cart right now!"
- continue
- # End the program if a user wants to leave
- elif selection == "3":
- end()
- break
- # Prints the main menu again if an invalid command was entered
- else:
- print "Invalid command, please try again."
- continue
Add Comment
Please, Sign In to add comment