Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def process_chocolate_and_milk(choc, milk, chocs, milks):
- conditions = {
- (True, True): lambda: None, # both are <= 0
- (True, False): lambda: milks.appendleft(milk), # chocolate <= 0
- (False, True): lambda: chocs.append(choc), # milk <= 0
- (False, False): lambda: None, # neither are <= 0
- }
- conditions[(choc <= 0, milk <= 0)]()
- def make_milkshake(choc, milk, chocs, milks, shakes):
- if choc == milk:
- shakes += 1
- else:
- milks.append(milk)
- choc -= 5
- chocs.append(choc)
- return shakes
- chocs = [int(x) for x in input().split(", ")]
- milks = deque([int(x) for x in input().split(", ")])
- shakes = 0
- while milks and chocs:
- if shakes == 5:
- break
- choc = chocs.pop()
- milk = milks.popleft()
- if choc <= 0 or milk <= 0:
- process_chocolate_and_milk(choc, milk, chocs, milks)
- else:
- shakes = make_milkshake(choc, milk, chocs, milks, shakes)
- print("Great! You made all the chocolate milkshakes needed!") if shakes == 5 else print("Not enough milkshakes.")
- print(f"Chocolate: {', '.join([str(x) for x in chocs])}") if chocs else print("Chocolate: empty")
- print(f"Milk: {', '.join([str(x) for x in milks])}") if milks else print("Milk: empty")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement