Guest User

Untitled

a guest
Jan 16th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.65 KB | None | 0 0
  1. # Final Project- Adrian Camano & Ryan Donaldson
  2.  
  3. # Import the UUID module to help us with generating a
  4. # unique transaction ID
  5. import uuid
  6.  
  7. # Generates a transaction ID
  8. def generate_transaction_id():
  9.     # Casts uuid object to a 128-bit hexadecimal string
  10.     fullUuid = uuid.uuid4().hex
  11.     # Only take the first section of the UUID to make it look more
  12.     # like a real transaction ID
  13.     transactionId = fullUuid[0:7]
  14.     # Returns the transaction ID as an upper case string
  15.     return transactionId.upper()
  16.    
  17. # Function that formats either of our inventories to print pretty
  18. def print_inventory(storage):
  19.     # If our dictionary is not empty, then format
  20.     if bool(storage):
  21.         # Iterate through our inventory to get the ID, title, and price of the item
  22.         for partId, inventory in storage.iteritems():
  23.             for title, price in inventory.iteritems():
  24.                 print "%s. %s - $%d" % (partId, title, price)
  25.     else:
  26.         # Print if our dictionary is empty
  27.         print "There is nothing in our inventory or nothing in your shopping cart right now!"
  28.        
  29. # Function that ends our program        
  30. def end():
  31.     print "Thank you for shopping with us!"
  32.     pass
  33.  
  34. # Stores all of our computer store parts, ID as key, another dictionary as a value
  35. # with title and price of the item
  36. parts = {
  37.     1: {"Logitech Keyboard": 100},
  38.     2: {"Logitech VX Nano Wireless Mouse": 280},
  39.     3: {"LG LCD LED Monitor": 650},
  40.     4: {"Asus SABERTOOTH Z97 Motherboard": 200},
  41.     5: {"Intel Core i7-5930K CPU": 580},
  42.     6: {"SAPPHIRE NITRO Radeon R9 390 Graphics Card": 340},
  43.     7: {"HIS Radeon R9 390 DirectX 12 System Fans": 320},
  44.     8: {"Thermaltake Core V71 Computer Case": 120},
  45.     9: {"Seagate Desktop HDD.15 Hard Drive": 130},
  46.     10: {"Microsoft Windows 10 Home-64bit-OEM": 100}
  47. }
  48.  
  49. # Stores all of the items in our shopping cart
  50. shopping_cart = {
  51.    
  52. }
  53.  
  54. print "Welcome!"
  55. print "\nPlease enter your username and password to begin."
  56.  
  57. # Stores our list of users
  58. allowed_users = ['ADMIN']
  59. # Stores our list of passwords for each user
  60. passwords = ['admin']
  61.  
  62. # Asks for a username to login with
  63. username = raw_input("Username: ")
  64. # Asks for a password to login with
  65. password = raw_input("Password: ")
  66.  
  67. # Controls if the user belongs to allowed_users, checks if a username or password
  68. # can be found in each of their respective arrays
  69. if username in allowed_users and password.lower() or password.upper() in passwords:
  70.     print "\nWelcome, Admin!"
  71. else:
  72.     # End the program if they entered a wrong username or password
  73.     print "\nAccess denied, please try again later!"
  74.     exit()
  75.  
  76. # Stores the user's current balance
  77. money = 1000.00
  78.  
  79. # Print amount of money in their balance when they login
  80. print "Thanks for logging in! You have currently $%s in your account." % money
  81.  
  82. # Loops main menu until break
  83. while True:
  84.     # Print menu selection
  85.     selection = raw_input("""What would you like to do?:
  86.    \t1) Browse Inventory
  87.    \t2) View Shopping Cart
  88.    \t3) Leave
  89.    """)
  90.  
  91.     if selection == "1":
  92.         # If user chooses to browse inventory, print the inventory and ask if they
  93.         # would like to purchase an item
  94.         while True:
  95.             print "Here is our current inventory:"
  96.             print_inventory(parts)
  97.             selection = int(raw_input("\nWhat would you like to purchase?: "))
  98.             # If the ID of the user input can be found in the array, add it to
  99.             # shopping cart
  100.             if selection in parts:
  101.                 # Gets the value based on the ID in the inventory
  102.                 inv = parts[selection]
  103.                 # Since there's 1 key & value for each value of our inventory
  104.                 # it's safe to access the 0th element and assign to a
  105.                 # variable for title & price
  106.                 title = inv.keys()[0]
  107.                 price = inv.values()[0]
  108.                 # Add a new element to our dictionary
  109.                 shopping_cart[title] = price
  110.                
  111.                 # Tell the user they have added the item to their shopping cart
  112.                 print "You have added %s - $%d to your shopping cart." % (title, price)
  113.            
  114.                 continuee = raw_input("\nWould you like to continue shopping?: ")
  115.                 # If user wants to continue shopping, repeat this inner while
  116.                 # loop. Else, start over and print the main menu again
  117.                 if continuee == "Yes":
  118.                     continue
  119.                 else:
  120.                     break
  121.     # If the user wants to view their shopping cart, format the dictionary
  122.     # to be a readable by the user, add each price value to their total
  123.     # price and then ask if they would like to checkout
  124.     elif selection == "2":
  125.         # Stores total price for all items
  126.         total_price = 0
  127.        
  128.         # If the user has items in their shopping cart, continue
  129.         if bool(shopping_cart):
  130.             # Formats our dictionary to tell the user what's in their shopping cart
  131.             print "Here is what's currently in your shopping cart:"
  132.             i = 0
  133.             for title, price in shopping_cart.iteritems():
  134.                 i = i + 1
  135.                 print "%s. %s - $%d" % (i, title, price)
  136.            
  137.             # Adds each price to their total price
  138.             for price in shopping_cart.values():
  139.                 total_price += price
  140.            
  141.             checkout = raw_input("\nWould you like to checkout?: ")
  142.             if checkout == "Yes":
  143.                 # If they choose to checkout, generate a transaction ID
  144.                 # and add sales tax & S+H to their cost
  145.                 transaction_id = generate_transaction_id()
  146.                 sales_tax = total_price * 0.07
  147.                 with_shipping_handling = total_price + sales_tax + 9.95
  148.                 # Print total cost & transaction
  149.                 print "\nTotal Cost: $%d" % (total_price)
  150.                 print "Total Cost w/ Sales Tax: $%d" % (total_price + sales_tax)
  151.                 print "Total Cost w/ Sales Tax & Shipping and Handling: $%d" % (with_shipping_handling)
  152.                 print "Transaction ID: %s" % (transaction_id)
  153.                
  154.                 # If they do not have money to purchase all the items, end the
  155.                 # program
  156.                 if money < with_shipping_handling:
  157.                     print "You do not have enough money to purchase all these items!"
  158.                     break
  159.                 else:
  160.                     # Clears all items from the shopping cart
  161.                     shopping_cart.clear()
  162.                     # Subtract total_price from their money
  163.                     money -= with_shipping_handling
  164.                     # Print their new balance
  165.                     print "Your balance is now: $%d" % (money)
  166.                
  167.                     # If they would like to continue shopping, print the main menu
  168.                     # again or else end the program
  169.                     continue_shopping = raw_input("\nWould you like to continue shopping?: ")
  170.                     if continue_shopping == "Yes":
  171.                         continue
  172.                     else:
  173.                         end()
  174.                         break
  175.         # If the user has no items in their shopping cart, go back to the main menu
  176.         else:
  177.             print "You do not have any items in your shopping cart right now!"
  178.             continue
  179.     # End the program if a user wants to leave
  180.     elif selection == "3":
  181.         end()
  182.         break
  183.     # Prints the main menu again if an invalid command was entered
  184.     else:
  185.         print "Invalid command, please try again."
  186.         continue
Add Comment
Please, Sign In to add comment