Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validate_input(subject, options, parse_func=lambda x: x):
- while True:
- try:
- x = parse_func(input(f'Enter {subject} ({"/".join(map(str, options))})\n>>> '))
- if x not in options: raise ValueError
- break
- except ValueError:
- print('Please enter a valid option')
- return x
- def percent_str(a, b):
- return str(round(a / b * 100, 1)) + '%'
- extra_topping_names = ['pepperoni', 'chicken', 'extracheese', 'mushrooms', 'spinach', 'olives']
- topping_counts = [0 for i in range(6)]
- total_ordered_pizzas = 0
- total_topping_count = 0
- while True:
- size = validate_input('pizza size', ['small', 'medium', 'large'], str.lower)
- base = validate_input('pizza base', ['thin', 'thick'], str.lower)
- extra_topping_count = validate_input('number of extra toppings', [0, 1, 2, 3], int)
- toppings = ['tomato', 'cheese']
- topping_options = extra_topping_names.copy()
- print('Default toppings: ' + ', '.join(toppings))
- for i in range(extra_topping_count):
- extra_topping = validate_input(f'extra topping {str(i+1)}', topping_options, str.lower)
- topping_options.remove(extra_topping)
- toppings.append(extra_topping)
- print(f'\nYour order is a {size} pizza with a {base} base')
- print('Your toppings are: ' + ', '.join(toppings))
- if input('\nEnter "confirm" to confirm your order: ').lower() == 'confirm':
- for i in range(6):
- if extra_topping_names[i] in toppings:
- topping_counts[i] += 1
- total_topping_count += extra_topping_count
- total_ordered_pizzas += 1
- print('\nYour order number is: ' + f'{total_ordered_pizzas:04d}')
- else:
- print('Order cancelled')
- if input('Enter "end" to end day: ').lower() == 'end': break
- if total_ordered_pizzas == 0:
- print('No pizzas ordered today')
- elif total_ordered_pizzas == 0:
- print('No extra toppings ordered today')
- else:
- max_topping_count = max(topping_counts)
- min_topping_count = min(topping_counts)
- popular_toppings = [extra_topping_names[i] for i in range(6) if topping_counts[i] == max_topping_count]
- unpopular_toppings = [extra_topping_names[i] for i in range(6) if topping_counts[i] == min_topping_count]
- print(' - '.join(['\nMost popular topping' +
- ('s' if len(popular_toppings) > 1 else ''),
- ', '.join(popular_toppings),
- percent_str(max_topping_count, total_topping_count)]))
- print(' - '.join(['Least popular topping' +
- ('s' if len(unpopular_toppings) > 1 else ''),
- ', '.join(unpopular_toppings),
- percent_str(min_topping_count, total_topping_count)]))
Add Comment
Please, Sign In to add comment