Advertisement
nein_yards

puzzaz.py

Dec 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. from enum import Enum
  2.  
  3. Size = Enum('Size', 'SMALL MEDIUM LARGE')
  4. Base = Enum('Base', 'THIN THICK')
  5. ExtraTopping = Enum('ExtraTopping', 'PEPPERONI CHICKEN EXTRA_CHEESE MUSHROOMS SPINACH OLIVES')
  6.  
  7. def yes_or_no(question):
  8. while True:
  9. reply = str(input(question + ' (y/n): ')).lower().strip()
  10. if reply[:1] == 'y': return True
  11. if reply[:1] == 'n': return False
  12.  
  13. def percent_string(fraction):
  14. return str(round(fraction * 100, 1)) + '%'
  15.  
  16. total_ordered_pizzas = 0
  17. pizza_topping_counts = [0 for i in range(6)]
  18. day_over = False
  19.  
  20. while not day_over:
  21. topping_names = ['TOMATOES', 'CHEESE']
  22. extra_topping_numbers = []
  23.  
  24. print('\nEnter pizza size')
  25. for i in range(1, 4):
  26. print(''.join(['\t', str(i), ': ', Size(i).name]))
  27. while True:
  28. try:
  29. pizza_size = Size(int(input('>>> ')))
  30. break
  31. except ValueError:
  32. print('Please enter a number between 1 and 3')
  33.  
  34. print('\nEnter pizza base')
  35. for i in range(1, 3):
  36. print(''.join(['\t', str(i), ': ', Base(i).name]))
  37. while True:
  38. try:
  39. pizza_base = Base(int(input('>>> ')))
  40. break
  41. except ValueError:
  42. print('Please enter a number between 1 and 2')
  43.  
  44. print('\nDefault toppings: ' + ', '.join(topping_names))
  45. while True:
  46. if len(topping_names) >= 5:
  47. break
  48. if not yes_or_no('Would you like any more toppings?'):
  49. break
  50.  
  51. print('\nEnter pizza topping')
  52. for i in range(1, 7):
  53. topping_name = ExtraTopping(i).name
  54. if topping_name in topping_names: continue
  55. print(''.join(['\t', str(i), ': ', topping_name]))
  56. while True:
  57. try:
  58. extra_topping_number = int(input('>>> '))
  59. topping_name = ExtraTopping(extra_topping_number).name
  60. if topping_name in topping_names: raise ValueError
  61. break
  62. except ValueError:
  63. print('Please enter a valid number')
  64. topping_names.append(topping_name)
  65. extra_topping_numbers.append(extra_topping_number)
  66.  
  67. print(f'\nYour order is a {pizza_size.name} pizza with a {pizza_base.name} base')
  68. print('Your toppings are: ' + ', '.join(topping_names))
  69.  
  70. if yes_or_no('\nWould you like to confirm your order?'):
  71. for extra_topping_number in extra_topping_numbers:
  72. pizza_topping_counts[extra_topping_number - 1] += 1
  73. total_ordered_pizzas += 1
  74. print('Your order number is: ' + f'{total_ordered_pizzas:04d}')
  75. else:
  76. print('Order cancelled')
  77.  
  78. day_over = yes_or_no('\nWould you like to end the day?')
  79.  
  80. print('\nTotal Ordered Pizzas: ' + str(total_ordered_pizzas))
  81.  
  82. total_topping_count = sum(pizza_topping_counts)
  83. if total_topping_count == 0:
  84. print('No extra toppings ordered today')
  85. quit()
  86.  
  87. min_topping_count = min(pizza_topping_counts)
  88. max_topping_count = max(pizza_topping_counts)
  89.  
  90. popular_toppings = []
  91. unpopular_toppings = []
  92.  
  93. for i in range(6):
  94. if pizza_topping_counts[i] == max_topping_count:
  95. popular_toppings.append(ExtraTopping(i + 1).name)
  96.  
  97. if pizza_topping_counts[i] == min_topping_count:
  98. unpopular_toppings.append(ExtraTopping(i + 1).name)
  99.  
  100. print(' - '.join(['Most popular topping' +
  101. ('s' if len(popular_toppings) > 1 else ''),
  102. ', '.join(popular_toppings),
  103. percent_string(max_topping_count / total_topping_count)]))
  104.  
  105. print(' - '.join(['Least popular topping' +
  106. ('s' if len(unpopular_toppings) > 1 else ''),
  107. ', '.join(unpopular_toppings),
  108. percent_string(min_topping_count / total_topping_count)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement