Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # data structures to store all phone data
- phone_item_codes = ["BPCM", "BPSH", "RPSS", "RPLL", "YPLS", "YPLL"]
- 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"]
- phone_prices = [29.99, 29.99, 199.99, 499.99, 549.99, 649.99]
- # data structures to store all tablet data
- tablet_item_codes = ["RTMS", "RTLM", "YTLM", "YTLL"]
- 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"]
- tablet_prices = [149.99, 299.99, 499.99, 599.99]
- # data structures to store all SIM card data
- sim_item_codes = ["SMNO", "SMPG"]
- sim_descriptions = ["SIM Free (no SIM card purchased)", "Pay As You Go (SIM card purchased)"]
- sim_prices = [0.00, 9.99]
- # data structures to store all case data
- case_item_codes = ["CSST", "CSLX"]
- case_descriptions = ["Standard", "Luxury"]
- case_prices = [0.00, 50.00]
- # data structures to store all charger data
- charger_item_codes = ["CGCR", "CGHM", "CGCRHM"]
- charger_descriptions = ["Car", "Home", "both car and home"]
- charger_prices = [19.99, 15.99, 35.98]
- def display_phones():
- component_format = '{: <2} {: <49} {} {:>7}' #{: <2} pad space for 2 chars, {:>4.2f} r-align 4 chars, 2 decimal places
- print("The following models of phone are available:")
- for description in phone_descriptions:
- print(component_format.format(phone_descriptions.index(description) + 1, description, "£", phone_prices[phone_descriptions.index(description)]))
- print()
- def choose_phone():
- choice = int(input("Which model of phone would you like (1 - 6)? "))
- while choice not in range(1, 7):
- choice = int(input("Invalid choice - please try again (1 - 6): "))
- print()
- return choice-1 # -1, so that value now represents correct index in list
- def display_tablets():
- output_format = '{: <2} {: <49} {} {:>7}'
- print("The following models of tablet are available:")
- for description in tablet_descriptions:
- print(output_format.format(tablet_descriptions.index(description) + 1, description, "£", tablet_prices[tablet_descriptions.index(description)]))
- print()
- def choose_tablet():
- choice = int(input("Which model of tablet would you like (1 - 4)? "))
- while choice not in range(1, 5):
- choice = int(input("Invalid choice - please try again (1 - 4): "))
- print()
- return choice-1 # -1, so that value now represents correct index in list
- def choose_device():
- choice = input("Do you want a phone or tablet (p / t)? ")
- print()
- while choice.lower() not in ["p", "t", "phone", "tablet"]:
- choice = input("Invalid choice - please try again (p / t): ")
- if choice == "p" or choice == "phone":
- display_phones()
- choice = choose_phone()
- device_choice = [phone_item_codes[choice-1], phone_descriptions[choice-1], phone_prices[choice-1]]
- elif choice == "t" or choice == "tablet":
- display_tablets()
- choice = choose_tablet()
- device_choice = [tablet_item_codes[choice-1], tablet_descriptions[choice-1], tablet_prices[choice-1]]
- else:
- print("Something has gone wrong - consider try-catch here.")
- return device_choice
- def display_sim():
- output_format = '{: <2} {: <49} {} {:>7}'
- print("The following models of SIM card are available:")
- for description in sim_descriptions:
- print(output_format.format(sim_descriptions.index(description) + 1, description, "£", sim_prices[sim_descriptions.index(description)]))
- print()
- def choose_sim():
- choice = int(input("Which SIM card would you like (1 / 2)? "))
- while choice not in range(1, 3):
- choice = int(input("Invalid choice - please try again (1 / 2): "))
- print()
- sim_choice = [sim_item_codes[choice-1], sim_descriptions[choice-1], sim_prices[choice-1]]
- return sim_choice
- def display_cases():
- output_format = '{: <2} {: <49} {} {:>7}'
- print("The following models of case are available:")
- for description in case_descriptions:
- print(output_format.format(case_descriptions.index(description) + 1, description, "£", case_prices[case_descriptions.index(description)]))
- print()
- def choose_case():
- choice = int(input("Which case would you like (1 / 2)? "))
- while choice not in range(1, 3):
- choice = int(input("Invalid choice - please try again (1 / 2): "))
- print()
- case_choice = [case_item_codes[choice-1], case_descriptions[choice-1], case_prices[choice-1]]
- return case_choice
- def display_chargers():
- output_format = '{: <2} {: <49} {} {:>7}'
- print("The following models of charger are available:")
- for description in charger_descriptions:
- print(output_format.format(charger_descriptions.index(description) + 1, description, "£", charger_prices[charger_descriptions.index(description)]))
- print()
- def choose_charger():
- choice = int(input("Which charger would you like (1 - 3)? "))
- while choice not in range(1, 4):
- choice = int(input("Invalid choice - please try again (1 - 3): "))
- print()
- charger_choice = [charger_item_codes[choice-1], charger_descriptions[choice-1], charger_prices[choice-1]]
- return charger_choice
- def sale_run(invoice, discount):
- device_choice = choose_device()
- device_choice[2] = device_choice[2] * discount
- invoice.append(device_choice)
- if device_choice[0] in phone_item_codes:
- display_sim()
- invoice.append(choose_sim())
- display_cases()
- invoice.append(choose_case())
- display_chargers()
- invoice.append(choose_charger())
- return invoice
- def print_invoice(invoice, running_total):
- invoice_format = '{: <6} {: <49} {} {:>7.2f}'
- total_format = '{: <56} {} {:>7.2f}'
- print("INVOICE")
- print("------------------------------------------------------------------")
- for item in invoice:
- print(invoice_format.format(item[0], item[1], "£", item[2], 2))
- running_total = running_total + item[2]
- print()
- print(total_format.format("Total price: ", "£", running_total, 2))
- def main():
- positive_choices = ["yes", "y"]
- negative_choices = ["no", "n"]
- running_total = 0
- invoice = []
- running = True
- discount = 1
- while running:
- sale_run(invoice, discount)
- choice = input("Do you want another device at 10% discount (y / n): ")
- print()
- while choice.lower() not in positive_choices and choice.lower() not in negative_choices:
- choice = input("Invalid choice, do you want another device (y / n): ")
- print()
- if choice.lower() in positive_choices:
- running = True
- discount = 0.9
- elif choice.lower() in negative_choices:
- running = False
- print_invoice(invoice, running_total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement