earlution

(adv) Task 1 - part 3

Nov 4th, 2021 (edited)
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 KB | None | 0 0
  1. components = ("Processor",
  2.               "RAM",
  3.               "Storage",
  4.               "Screen",
  5.               "Case",
  6.               "USB ports")
  7. choices = ("P3",
  8.            "P5",
  9.            "P7",
  10.            "16GB",
  11.            "32GB",
  12.            "1TB",
  13.            "2TB",
  14.            "19\"",
  15.            "23\"",
  16.            "Mini Tower",
  17.            "Midi Tower",
  18.            "2 ports",
  19.            "4 ports")
  20. prices = (100, 120, 200, 75, 150, 50, 100, 65, 120, 40, 70, 10, 20)
  21.  
  22.  
  23. def get_components_sublist(component, case):
  24.     if component == "Processor":
  25.         if case == "upper":
  26.             subcomponents = choices[:3]
  27.         elif case == "lower":
  28.             subcomponents = [processor.lower() for processor in choices[:3]]
  29.     elif component == "RAM":
  30.         if case == "upper":
  31.             subcomponents = choices[3:5]
  32.         elif case == "lower":
  33.             subcomponents = [ram.lower()  for ram in choices[3:5]]
  34.     elif component == "Storage":
  35.         if case == "upper":
  36.             subcomponents = choices[5:7]
  37.         elif case == "lower":
  38.             subcomponents = [storage.lower()  for storage in choices[5:7]]
  39.     elif component == "Screen":
  40.         if case == "upper":
  41.             subcomponents = choices[7:9]
  42.         elif case == "lower":
  43.             subcomponents = [screen.lower()  for screen in choices[7:9]]
  44.     elif component == "Case":
  45.         if case == "upper":
  46.             subcomponents = choices[9:11]
  47.         elif case == "lower":
  48.             subcomponents = [case.lower()  for case in choices[9:11]]      
  49.     elif component == "USB Ports":
  50.         if case == "upper":
  51.             subcomponents = choices[11:]
  52.         elif case == "lower":
  53.             subcomponents = [usb_port.lower()  for usb_port in choices[11:]]        
  54.     return subcomponents
  55.  
  56.  
  57. def get_prices_sublist(component):
  58.     if component == "Processor":
  59.         subprices = prices[:3]
  60.     elif component == "RAM":
  61.         subprices = prices[3:5]
  62.     elif component == "Storage":
  63.         subprices = prices[5:7]
  64.     elif component == "Screen":
  65.         subprices = prices[7:9]
  66.     elif component == "Case":
  67.         subprices = prices[9:11]
  68.     elif component == "USB Ports":
  69.         subprices = prices[11:]
  70.     return subprices
  71.  
  72.  
  73. def output_component_info(component, subcomponents, subprices):
  74.     print(component)
  75.     print("Your choices (with prices) are: ")
  76.     for choice, price in zip(subcomponents, subprices):
  77.         print(choice, str(price))
  78.    
  79.  
  80. def get_component_choice(component, subcomponents):
  81.     component_choice: str = input("Make your choice: ")
  82.     while component_choice.lower() not in subcomponents:
  83.         print("That is not a valid choice of " + component)
  84.         component_choice: str = input("Please choose again: ")
  85.     print()
  86.     return component_choice
  87.  
  88.        
  89. def main():
  90.     processor_choices = get_components_sublist("Processor", "upper")
  91.     processor_prices = get_prices_sublist("Processor")
  92.     output_component_info("Processor", processor_choices, processor_prices)
  93.     processor_choices = get_components_sublist("Processor", "lower")
  94.     processor_choice = get_component_choice("Processor", processor_choices)
  95.  
  96.     ram_choices = get_components_sublist("RAM", "upper")
  97.     ram_prices = get_prices_sublist("RAM")
  98.     output_component_info("RAM", ram_choices, ram_prices)
  99.     ram_choices = get_components_sublist("RAM", "lower")
  100.     ram_prices = get_component_choice("RAM", ram_choices)
  101.  
  102.     storage_choices = get_components_sublist("Storage", "upper")
  103.     storage_prices = get_prices_sublist("Storage")
  104.     output_component_info("Storage", storage_choices, storage_prices)
  105.     storage_choices = get_components_sublist("Storage", "lower")
  106.     storage_prices = get_component_choice("Storage", storage_choices)
  107.  
  108.  
  109.  
  110.    
  111.    
  112.  
Add Comment
Please, Sign In to add comment