Advertisement
George_Ivanov05

0.3

Sep 20th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def if_chocolates_left(chocolate: list):
  5.     if len(chocolate) > 0:
  6.         return f"Chocolate: {', '.join([str(i) for i in chocolate])}"
  7.     else:
  8.         return "Chocolate: empty"
  9.  
  10.  
  11. def if_cups_milk_left(milk):
  12.     if len(milk) > 0:
  13.         return f"Milk: {', '.join([str(i) for i in milk])}"
  14.     else:
  15.         return "Milk: empty"
  16.  
  17.  
  18. chocolates = [int(x) for x in input().split(", ")]
  19. cups__milk = [int(x) for x in input().split(", ")]
  20.  
  21. chocolate_stack = []
  22. cups_milk_queue = deque(cups__milk)
  23.  
  24. for i in chocolates:
  25.     chocolate_stack.append(i)
  26.  
  27. counter = 0
  28. while True:
  29.     if counter == 5:
  30.         break
  31.     if len(cups_milk_queue) > 0 and len(chocolate_stack) > 0:
  32.         current_chocolate = chocolate_stack.pop()
  33.         current_cup_milk = cups_milk_queue.popleft()
  34.         if current_chocolate > 0 and current_cup_milk > 0:
  35.             if current_chocolate == current_cup_milk:
  36.                 counter += 1
  37.             else:
  38.                 cups_milk_queue.append(current_cup_milk)
  39.                 current_chocolate -= 5
  40.                 if current_chocolate > 0:
  41.                     chocolate_stack.append(current_chocolate)
  42.         else:
  43.             if current_chocolate < 0:
  44.                 cups_milk_queue.appendleft(current_cup_milk)
  45.             elif current_cup_milk < 0:
  46.                 chocolate_stack.append(current_chocolate)
  47.     else:
  48.         break
  49.  
  50. if counter == 5:
  51.     print(f"Great! You made all the chocolate milkshakes needed!")
  52.  
  53. else:
  54.     print(f"Not enough milkshakes.")
  55.  
  56. print(if_chocolates_left(chocolate_stack))
  57. print(if_cups_milk_left(cups_milk_queue))
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement