Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from enum import Enum
- Size = Enum('Size', 'SMALL MEDIUM LARGE')
- Base = Enum('Base', 'THIN THICK')
- ExtraTopping = Enum('ExtraTopping', 'PEPPERONI CHICKEN EXTRA_CHEESE MUSHROOMS SPINACH OLIVES')
- def yes_or_no(question):
- while True:
- reply = str(input(question + ' (y/n): ')).lower().strip()
- if reply[:1] == 'y': return True
- if reply[:1] == 'n': return False
- def percent_string(fraction):
- return str(round(fraction * 100, 1)) + '%'
- total_ordered_pizzas = 0
- pizza_topping_counts = [0 for i in range(6)]
- day_over = False
- while not day_over:
- topping_names = ['TOMATOES', 'CHEESE']
- extra_topping_numbers = []
- print('\nEnter pizza size')
- for i in range(1, 4):
- print(''.join(['\t', str(i), ': ', Size(i).name]))
- while True:
- try:
- pizza_size = Size(int(input('>>> ')))
- break
- except ValueError:
- print('Please enter a number between 1 and 3')
- print('\nEnter pizza base')
- for i in range(1, 3):
- print(''.join(['\t', str(i), ': ', Base(i).name]))
- while True:
- try:
- pizza_base = Base(int(input('>>> ')))
- break
- except ValueError:
- print('Please enter a number between 1 and 2')
- print('\nDefault toppings: ' + ', '.join(topping_names))
- while True:
- if len(topping_names) >= 5:
- break
- if not yes_or_no('Would you like any more toppings?'):
- break
- print('\nEnter pizza topping')
- for i in range(1, 7):
- topping_name = ExtraTopping(i).name
- if topping_name in topping_names: continue
- print(''.join(['\t', str(i), ': ', topping_name]))
- while True:
- try:
- extra_topping_number = int(input('>>> '))
- topping_name = ExtraTopping(extra_topping_number).name
- if topping_name in topping_names: raise ValueError
- break
- except ValueError:
- print('Please enter a valid number')
- topping_names.append(topping_name)
- extra_topping_numbers.append(extra_topping_number)
- print(f'\nYour order is a {pizza_size.name} pizza with a {pizza_base.name} base')
- print('Your toppings are: ' + ', '.join(topping_names))
- if yes_or_no('\nWould you like to confirm your order?'):
- for extra_topping_number in extra_topping_numbers:
- pizza_topping_counts[extra_topping_number - 1] += 1
- total_ordered_pizzas += 1
- print('Your order number is: ' + f'{total_ordered_pizzas:04d}')
- else:
- print('Order cancelled')
- day_over = yes_or_no('\nWould you like to end the day?')
- print('\nTotal Ordered Pizzas: ' + str(total_ordered_pizzas))
- total_topping_count = sum(pizza_topping_counts)
- if total_topping_count == 0:
- print('No extra toppings ordered today')
- quit()
- min_topping_count = min(pizza_topping_counts)
- max_topping_count = max(pizza_topping_counts)
- popular_toppings = []
- unpopular_toppings = []
- for i in range(6):
- if pizza_topping_counts[i] == max_topping_count:
- popular_toppings.append(ExtraTopping(i + 1).name)
- if pizza_topping_counts[i] == min_topping_count:
- unpopular_toppings.append(ExtraTopping(i + 1).name)
- print(' - '.join(['Most popular topping' +
- ('s' if len(popular_toppings) > 1 else ''),
- ', '.join(popular_toppings),
- percent_string(max_topping_count / total_topping_count)]))
- print(' - '.join(['Least popular topping' +
- ('s' if len(unpopular_toppings) > 1 else ''),
- ', '.join(unpopular_toppings),
- percent_string(min_topping_count / total_topping_count)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement