Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def char_to_size(size_char):
- if size_char == 's': return 'small'
- if size_char == 'm': return 'medium'
- if size_char == 'l': return 'large'
- def error_message(): print("Please enter a valid choice.")
- pizza_toppings = [
- "pepperoni",
- "chicken",
- "extra cheese",
- "mushrooms",
- "spinach",
- "olives"
- ]
- total_ordered_pizzas = 0
- total_topping_count = 0
- pizza_topping_counts = [0] * 6
- day_over = False
- while not day_over:
- pizza_confirmed = False
- topping_list = ["tomato", "cheese"]
- current_topping_counts = [0 for i in range(6)]
- while True:
- pizza_size_char = input("Enter pizza size (s/m/l): ").lower()
- if pizza_size_char in ["s", "m", "l"]:
- break
- error_message()
- pizza_size = char_to_size(pizza_size_char)
- while True:
- pizza_base_option = input("Would you like a thin base over a thick base? (Y/N): ").upper()
- if pizza_base_option == "Y" or pizza_base_option == "N":
- break
- error_message()
- pizza_base = "thin base" if pizza_base_option == "Y" else "thick base"
- print("You have tomato and cheese toppings by default on your pizza.")
- topping_choice_number = 0
- while True:
- if len(topping_list) == 5: break
- any_more_toppings = input("Would you like any more toppings? (Y/N): ").upper() == "Y"
- if not any_more_toppings:
- break
- while True:
- [print(i + 1, pizza_toppings[i]) for i in range(len(pizza_toppings))]
- topping_choice_number = int(input("Enter a number from 1-6 to choose a topping: "))
- if 1 <= topping_choice_number <= 6:
- topping_index = topping_choice_number - 1
- if pizza_toppings[topping_index] not in topping_list:
- topping_list.append(pizza_toppings[topping_index])
- current_topping_counts[topping_index] = 1
- break
- error_message()
- print("Your order is a {0} pizza with a {1}".format(pizza_size, pizza_base))
- print("Your toppings are " + ", ".join(topping_list))
- pizza_confirmed = input('Enter "confirm" to confirm your order: ').lower() == "confirm"
- if pizza_confirmed:
- for i, current_topping_count in enumerate(current_topping_counts):
- pizza_topping_counts[i] += current_topping_count
- total_topping_count += current_topping_count
- total_ordered_pizzas += 1
- print("Your order number is: " + f"{total_ordered_pizzas:04d}")
- else:
- print("Order cancelled.")
- day_over = input('Enter "end" to end the day: ').lower() == "end"
- if total_topping_count == 0:
- print("No additional toppings ordered today.")
- else:
- min_topping_count, max_topping_count = 2 ** 31 - 1, -2 ** 31 + 1
- for i in range(len(pizza_topping_counts)):
- if pizza_topping_counts[i] > max_topping_count:
- max_topping_count = pizza_topping_counts[i]
- popular_topping_index = i
- if pizza_topping_counts[i] < min_topping_count:
- min_topping_count = pizza_topping_counts[i]
- unpopular_topping_index = i
- popular_topping = pizza_toppings[popular_topping_index]
- popular_topping_percent = str(round(max_topping_count / total_topping_count * 100, 2)) + "%"
- unpopular_topping = pizza_toppings[unpopular_topping_index]
- unpopular_topping_percent = str(round(min_topping_count / total_topping_count * 100, 2)) + "%"
- print(" - ".join(["Most popular topping",
- popular_topping,
- popular_topping_percent]))
- print(" - ".join(["Least popular topping",
- unpopular_topping,
- unpopular_topping_percent]))
- print("Total Ordered Pizzas:", total_ordered_pizzas)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement