Advertisement
earlution

2020_pre-release.py

Jun 17th, 2022
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.04 KB | None | 0 0
  1. # data structures to store all phone data
  2. phone_item_codes = ["BPCM", "BPSH", "RPSS", "RPLL", "YPLS", "YPLL"]
  3. phone_descriptions = ["Compact", "Clam Shell", "RoboPhone – 5-inch screen and 64 GB memory", "RoboPhone – 6-inch screen and 256 GB memory", "Y-Phone Standard – 6-inch screen and 64 GB memory", "Y-Phone Deluxe – 6-inch screen and 256 GB memory"]
  4. phone_prices = [29.99, 29.99, 199.99, 499.99, 549.99, 649.99]
  5.  
  6. # data structures to store all tablet data
  7. tablet_item_codes = ["RTMS", "RTLM", "YTLM", "YTLL"]
  8. tablet_descriptions = ["RoboTab – 8-inch screen and 64 GB memory", "RoboTab – 10-inch screen and 128 GB memory", "Y-Tab Standard – 10-inch screen and 128 GB memory", "Y-Tab Deluxe – 10-inch screen and 256 GB memory"]
  9. tablet_prices = [149.99, 299.99, 499.99, 599.99]
  10.  
  11. # data structures to store all SIM card data
  12. sim_item_codes = ["SMNO", "SMPG"]
  13. sim_descriptions = ["SIM Free (no SIM card purchased)", "Pay As You Go (SIM card purchased)"]
  14. sim_prices = [0.00, 9.99]
  15.  
  16. # data structures to store all case data
  17. case_item_codes = ["CSST", "CSLX"]
  18. case_descriptions = ["Standard", "Luxury"]
  19. case_prices = [0.00, 50.00]
  20.  
  21. # data structures to store all charger data
  22. charger_item_codes = ["CGCR", "CGHM", "CGCRHM"]
  23. charger_descriptions = ["Car", "Home", "both car and home"]
  24. charger_prices = [19.99, 15.99, 35.98]
  25.  
  26. def display_phones():
  27.     component_format = '{: <2} {: <49} {} {:>7}' #{: <2} pad space for 2 chars, {:>4.2f} r-align 4 chars, 2 decimal places
  28.     print("The following models of phone are available:")
  29.     for description in phone_descriptions:
  30.         print(component_format.format(phone_descriptions.index(description) + 1, description, "£", phone_prices[phone_descriptions.index(description)]))
  31.     print()
  32.  
  33. def choose_phone():
  34.     choice = int(input("Which model of phone would you like (1 - 6)? "))
  35.     while choice not in range(1, 7):
  36.         choice = int(input("Invalid choice - please try again (1 - 6): "))
  37.     print()
  38.     return choice-1 # -1, so that value now represents correct index in list
  39.  
  40. def display_tablets():
  41.     output_format = '{: <2} {: <49} {} {:>7}'
  42.     print("The following models of tablet are available:")
  43.     for description in tablet_descriptions:
  44.         print(output_format.format(tablet_descriptions.index(description) + 1, description, "£", tablet_prices[tablet_descriptions.index(description)]))
  45.     print()
  46.  
  47. def choose_tablet():
  48.     choice = int(input("Which model of tablet would you like (1 - 4)? "))
  49.     while choice not in range(1, 5):
  50.         choice = int(input("Invalid choice - please try again (1 - 4): "))
  51.     print()
  52.     return choice-1 # -1, so that value now represents correct index in list
  53.  
  54. def choose_device():
  55.     choice = input("Do you want a phone or tablet (p / t)? ")
  56.     print()
  57.     while choice.lower() not in ["p", "t", "phone", "tablet"]:
  58.         choice = input("Invalid choice - please try again (p / t): ")
  59.     if choice == "p" or choice == "phone":
  60.         display_phones()
  61.         choice = choose_phone()
  62.         device_choice = [phone_item_codes[choice-1], phone_descriptions[choice-1], phone_prices[choice-1]]
  63.     elif choice == "t" or choice == "tablet":
  64.         display_tablets()
  65.         choice = choose_tablet()
  66.         device_choice = [tablet_item_codes[choice-1], tablet_descriptions[choice-1], tablet_prices[choice-1]]
  67.     else:
  68.         print("Something has gone wrong - consider try-catch here.")    
  69.     return device_choice
  70.  
  71. def display_sim():
  72.     output_format = '{: <2} {: <49} {} {:>7}'
  73.     print("The following models of SIM card are available:")
  74.     for description in sim_descriptions:
  75.         print(output_format.format(sim_descriptions.index(description) + 1, description, "£", sim_prices[sim_descriptions.index(description)]))
  76.     print()
  77.  
  78. def choose_sim():
  79.     choice = int(input("Which SIM card would you like (1 / 2)? "))
  80.     while choice not in range(1, 3):
  81.         choice = int(input("Invalid choice - please try again (1 / 2): "))
  82.     print()
  83.     sim_choice = [sim_item_codes[choice-1], sim_descriptions[choice-1], sim_prices[choice-1]]
  84.     return sim_choice
  85.  
  86. def display_cases():
  87.     output_format = '{: <2} {: <49} {} {:>7}'
  88.     print("The following models of case are available:")
  89.     for description in case_descriptions:
  90.         print(output_format.format(case_descriptions.index(description) + 1, description, "£", case_prices[case_descriptions.index(description)]))
  91.     print()
  92.  
  93. def choose_case():
  94.     choice = int(input("Which case would you like (1 / 2)? "))
  95.     while choice not in range(1, 3):
  96.         choice = int(input("Invalid choice - please try again (1 / 2): "))
  97.     print()
  98.     case_choice = [case_item_codes[choice-1], case_descriptions[choice-1], case_prices[choice-1]]
  99.     return case_choice
  100.  
  101. def display_chargers():
  102.     output_format = '{: <2} {: <49} {} {:>7}'
  103.     print("The following models of charger are available:")
  104.     for description in charger_descriptions:
  105.         print(output_format.format(charger_descriptions.index(description) + 1, description, "£", charger_prices[charger_descriptions.index(description)]))
  106.     print()
  107.  
  108. def choose_charger():
  109.     choice = int(input("Which charger would you like (1 - 3)? "))
  110.     while choice not in range(1, 4):
  111.         choice = int(input("Invalid choice - please try again (1 - 3): "))
  112.     print()
  113.     charger_choice = [charger_item_codes[choice-1], charger_descriptions[choice-1], charger_prices[choice-1]]
  114.     return charger_choice
  115.  
  116. def sale_run(invoice, discount):
  117.     device_choice = choose_device()
  118.     device_choice[2] = device_choice[2] * discount
  119.     invoice.append(device_choice)
  120.     if device_choice[0] in phone_item_codes:
  121.         display_sim()
  122.         invoice.append(choose_sim())
  123.     display_cases()
  124.     invoice.append(choose_case())
  125.     display_chargers()
  126.     invoice.append(choose_charger())
  127.     return invoice
  128.  
  129. def print_invoice(invoice, running_total):
  130.     invoice_format = '{: <6} {: <49} {} {:>7.2f}'
  131.     total_format = '{: <56} {} {:>7.2f}'
  132.     print("INVOICE")
  133.     print("------------------------------------------------------------------")
  134.     for item in invoice:
  135.         print(invoice_format.format(item[0], item[1], "£", item[2], 2))
  136.         running_total = running_total + item[2]
  137.     print()
  138.     print(total_format.format("Total price: ", "£", running_total, 2))
  139.  
  140. def main():
  141.     positive_choices = ["yes", "y"]
  142.     negative_choices = ["no", "n"]
  143.     running_total = 0
  144.     invoice = []
  145.     running = True
  146.     discount = 1
  147.    
  148.     while running:
  149.         sale_run(invoice, discount)
  150.         choice = input("Do you want another device at 10% discount (y / n): ")
  151.         print()
  152.         while choice.lower() not in positive_choices and choice.lower() not in negative_choices:
  153.             choice = input("Invalid choice, do you want another device (y / n): ")
  154.             print()
  155.         if choice.lower() in positive_choices:
  156.             running = True
  157.             discount = 0.9
  158.         elif choice.lower() in negative_choices:
  159.             running = False
  160.    
  161.     print_invoice(invoice, running_total)
  162.  
  163.  
  164.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement