Advertisement
GeorgiLukanov87

Python Advanced Exam - 25 June 2022

Sep 15th, 2022 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.39 KB | None | 0 0
  1. # Python Advanced Exam - 25 June 2022
  2.  
  3. # https://judge.softuni.org/Contests/Practice/Index/3515#0
  4.  
  5. # 01. Collecting Eggs
  6. # 02. Exit Founder
  7. # 03. Shopping Cart
  8.  
  9. ----------------------------------------------------------------------------------------------------------
  10.  
  11. # 01. Collecting Eggs
  12.  
  13.  
  14. from collections import deque
  15.  
  16. eggs = deque([int(x) for x in input().split(', ')])  # FIFI -> starts from index[0]
  17. paper = deque([int(x) for x in input().split(', ')])  # LIFO -> starts from index[-1]
  18. box = 0
  19. while True:
  20.     if not eggs or not paper:
  21.         break
  22.  
  23.     first_egg = eggs[0]
  24.     last_paper = paper[-1]
  25.  
  26.     if first_egg <= 0 or first_egg == 13:
  27.         if first_egg == 13:
  28.             paper[0], paper[-1] = paper[-1], paper[0]
  29.         eggs.popleft()
  30.         continue
  31.  
  32.     result = eggs.popleft() + paper.pop()
  33.     if result <= 50:
  34.         box += 1
  35.  
  36. if box > 0:
  37.     print(f"Great! You filled {box} boxes.")
  38. else:
  39.     print("Sorry! You couldn't fill any boxes!")
  40.  
  41. if eggs:
  42.     print(f'Eggs left: {", ".join(str(x) for x in eggs)}')
  43. if paper:
  44.     print(f'Pieces of paper left: {", ".join(str(x) for x in paper)}')
  45.  
  46.  
  47. ----------------------------------------------------------------------------------------------------------
  48.  
  49.  
  50.  
  51. # 02. Exit Founder
  52. # NEW VERSION !
  53.  
  54.  
  55. from collections import deque
  56.  
  57. players = deque(input().split(', '))
  58. SIZE = 6
  59. matrix = []
  60. for _ in range(SIZE):
  61.     matrix.append(input().split())
  62.  
  63. wall_hit = {'Tom': 0, 'Jerry': 0}
  64. while True:
  65.     current_player = players[0]
  66.     row, col = eval(input())
  67.     if wall_hit[current_player] >= 1:
  68.         wall_hit[current_player] -= 1
  69.         players.rotate()
  70.         continue
  71.     if matrix[row][col] == 'E':
  72.         print(f"{current_player} found the Exit and wins the game!")
  73.         break
  74.     elif matrix[row][col] == 'W':
  75.         print(f'{current_player} hits a wall and needs to rest.')
  76.         wall_hit[current_player] += 1
  77.     elif matrix[row][col] == 'T':
  78.         print(f'{current_player} is out of the game! The winner is {players[1]}.')
  79.         break
  80.  
  81.     players.rotate()
  82.  
  83.  
  84. ==========================================================================================================
  85.  
  86.  
  87. # 02. Exit Founder
  88. # OLD VERSION !
  89.  
  90. player1, player2 = input().split(", ")
  91. matrix = []
  92. names = [player1, player2]
  93.  
  94. for row_index in range(6):
  95.     matrix.append(input().split())
  96.  
  97. player1_skip_next_turn = False
  98. player2_skip_next_turn = False
  99.  
  100. turns = 0
  101. while True:
  102.     turns += 1
  103.     if turns % 2 != 0:
  104.         current_player = player1
  105.     else:
  106.         current_player = player2
  107.  
  108.     command = eval(input())
  109.  
  110.     if turns % 2 != 0 and player1_skip_next_turn:
  111.         player1_skip_next_turn = False
  112.         continue
  113.     elif turns % 2 == 0 and player2_skip_next_turn:
  114.         player2_skip_next_turn = False
  115.         continue
  116.  
  117.     row, col = command[0], command[1]
  118.     current_step = matrix[row][col]
  119.  
  120.     if current_step == 'E':
  121.         print(f'{current_player} found the Exit and wins the game!')
  122.         break
  123.  
  124.     elif current_step == 'T':
  125.         names.remove(current_player)
  126.         print(f'{current_player} is out of the game! The winner is {"".join(names)}.')
  127.         break
  128.  
  129.     elif current_step == 'W':
  130.         if turns % 2 != 0:
  131.             player1_skip_next_turn = True
  132.         else:
  133.             player2_skip_next_turn = True
  134.         print(f"{current_player} hits a wall and needs to rest.")
  135.  
  136.  
  137. ----------------------------------------------------------------------------------------------------------
  138.  
  139. # 03. Shopping Cart
  140.  
  141.  
  142. def shopping_cart(*args):
  143.     limit = {'Pizza': 4, 'Soup': 3, 'Dessert': 2}
  144.     prepared = {'Pizza': [], 'Soup': [], 'Dessert': []}
  145.     orders = 0
  146.     for el in args:
  147.         if el == 'Stop':
  148.             if orders == 0:
  149.                 return 'No products in the cart!'
  150.             break
  151.  
  152.         dish, product = el
  153.         if product not in prepared[dish]:
  154.             if len(prepared[dish]) < limit[dish]:
  155.                 prepared[dish] += [product]
  156.                 orders += 1
  157.  
  158.     final_print = ""
  159.  
  160.     for dish, product in sorted(prepared.items(), key=lambda x: (-len(x[1]), x[0])):
  161.         final_print += f'{dish}:\n'
  162.         for el in sorted(product):
  163.             final_print += f' - {el}\n'
  164.  
  165.     return final_print
  166.  
  167.  
  168. ----------------------------------------------------------------------------------------------------------
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement