Advertisement
nein_yards

pizza.py

Dec 28th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. def char_to_size(size_char):
  2. if size_char == 's': return 'small'
  3. if size_char == 'm': return 'medium'
  4. if size_char == 'l': return 'large'
  5.  
  6.  
  7. def error_message(): print("Please enter a valid choice.")
  8.  
  9.  
  10. pizza_toppings = [
  11. "pepperoni",
  12. "chicken",
  13. "extra cheese",
  14. "mushrooms",
  15. "spinach",
  16. "olives"
  17. ]
  18.  
  19. total_ordered_pizzas = 0
  20. total_topping_count = 0
  21. pizza_topping_counts = [0] * 6
  22. day_over = False
  23.  
  24. while not day_over:
  25. pizza_confirmed = False
  26. topping_list = ["tomato", "cheese"]
  27. current_topping_counts = [0 for i in range(6)]
  28.  
  29. while True:
  30. pizza_size_char = input("Enter pizza size (s/m/l): ").lower()
  31. if pizza_size_char in ["s", "m", "l"]:
  32. break
  33. error_message()
  34. pizza_size = char_to_size(pizza_size_char)
  35.  
  36. while True:
  37. pizza_base_option = input("Would you like a thin base over a thick base? (Y/N): ").upper()
  38. if pizza_base_option == "Y" or pizza_base_option == "N":
  39. break
  40. error_message()
  41. pizza_base = "thin base" if pizza_base_option == "Y" else "thick base"
  42.  
  43. print("You have tomato and cheese toppings by default on your pizza.")
  44. topping_choice_number = 0
  45. while True:
  46. if len(topping_list) == 5: break
  47. any_more_toppings = input("Would you like any more toppings? (Y/N): ").upper() == "Y"
  48. if not any_more_toppings:
  49. break
  50. while True:
  51. [print(i + 1, pizza_toppings[i]) for i in range(len(pizza_toppings))]
  52. topping_choice_number = int(input("Enter a number from 1-6 to choose a topping: "))
  53. if 1 <= topping_choice_number <= 6:
  54. topping_index = topping_choice_number - 1
  55. if pizza_toppings[topping_index] not in topping_list:
  56. topping_list.append(pizza_toppings[topping_index])
  57. current_topping_counts[topping_index] = 1
  58. break
  59. error_message()
  60.  
  61. print("Your order is a {0} pizza with a {1}".format(pizza_size, pizza_base))
  62. print("Your toppings are " + ", ".join(topping_list))
  63.  
  64. pizza_confirmed = input('Enter "confirm" to confirm your order: ').lower() == "confirm"
  65. if pizza_confirmed:
  66. for i, current_topping_count in enumerate(current_topping_counts):
  67. pizza_topping_counts[i] += current_topping_count
  68. total_topping_count += current_topping_count
  69. total_ordered_pizzas += 1
  70. print("Your order number is: " + f"{total_ordered_pizzas:04d}")
  71. else:
  72. print("Order cancelled.")
  73. day_over = input('Enter "end" to end the day: ').lower() == "end"
  74.  
  75. if total_topping_count == 0:
  76. print("No additional toppings ordered today.")
  77. else:
  78. min_topping_count, max_topping_count = 2 ** 31 - 1, -2 ** 31 + 1
  79.  
  80. for i in range(len(pizza_topping_counts)):
  81. if pizza_topping_counts[i] > max_topping_count:
  82. max_topping_count = pizza_topping_counts[i]
  83. popular_topping_index = i
  84.  
  85. if pizza_topping_counts[i] < min_topping_count:
  86. min_topping_count = pizza_topping_counts[i]
  87. unpopular_topping_index = i
  88.  
  89. popular_topping = pizza_toppings[popular_topping_index]
  90. popular_topping_percent = str(round(max_topping_count / total_topping_count * 100, 2)) + "%"
  91.  
  92. unpopular_topping = pizza_toppings[unpopular_topping_index]
  93. unpopular_topping_percent = str(round(min_topping_count / total_topping_count * 100, 2)) + "%"
  94.  
  95. print(" - ".join(["Most popular topping",
  96. popular_topping,
  97. popular_topping_percent]))
  98.  
  99. print(" - ".join(["Least popular topping",
  100. unpopular_topping,
  101. unpopular_topping_percent]))
  102.  
  103. print("Total Ordered Pizzas:", total_ordered_pizzas)
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement