Advertisement
GeorgiLukanov87

Python Advanced Exam - 23 October 2021

Sep 12th, 2022 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.23 KB | None | 0 0
  1. # Python Advanced Exam - 23 October 2021
  2.  
  3. # https://judge.softuni.org/Contests/Practice/Index/3227#2
  4.  
  5. # 01. Aladdin's Gifts
  6. # 02. Ball in the Bucket
  7. # 03. Shopping List
  8.  
  9. ------------------------------------------------------------------------------------------
  10.  
  11. # 01. Aladdin's Gifts
  12.  
  13. from collections import deque
  14.  
  15.  
  16. def craft_gift_func(current_result):
  17.     if 100 <= current_result <= 199:
  18.         gifts['Gemstone'] += 1
  19.     elif 200 <= current_result <= 299:
  20.         gifts['Porcelain Sculpture'] += 1
  21.     elif 300 <= current_result <= 399:
  22.         gifts['Gold'] += 1
  23.     elif 400 <= current_result <= 499:
  24.         gifts['Diamond Jewellery'] += 1
  25.  
  26.  
  27. materials = deque([int(x) for x in input().split()])
  28. magic_values = deque([int(x) for x in input().split()])
  29. gifts = {'Diamond Jewellery': 0, 'Gemstone': 0, 'Gold': 0, 'Porcelain Sculpture': 0}
  30.  
  31. while True:
  32.     if not materials or not magic_values:
  33.         break
  34.     last_material = materials[-1]
  35.     first_magic_value = magic_values[0]
  36.     result = last_material + first_magic_value
  37.  
  38.     if result >= 100:
  39.         craft_gift_func(result)
  40.  
  41.     elif result < 100:
  42.         if result % 2 == 0:
  43.             result = last_material * 2 + first_magic_value * 3
  44.         else:
  45.             result *= 2
  46.  
  47.         craft_gift_func(result)
  48.  
  49.     if result > 499:
  50.         result /= 2
  51.         craft_gift_func(result)
  52.  
  53.     materials.pop()
  54.     magic_values.popleft()
  55.  
  56. success = False
  57. if gifts['Gemstone'] > 0 and gifts['Porcelain Sculpture'] > 0:
  58.     success = True
  59. if gifts['Gold'] > 0 and gifts['Diamond Jewellery'] > 0:
  60.     success = True
  61.  
  62. if success:
  63.     print("The wedding presents are made!")
  64. else:
  65.     print("Aladdin does not have enough wedding presents.")
  66.  
  67. if materials:
  68.     print(f'Materials left: {", ".join(str(m) for m in materials)}')
  69. if magic_values:
  70.     print(f"Magic left: {', '.join(str(v) for v in magic_values)}")
  71.  
  72. for name, count in gifts.items():
  73.     if count:
  74.         print(f'{name}: {count}')
  75.  
  76.  
  77. ------------------------------------------------------------------------------------------
  78. # 02. Ball in the Bucket
  79. # NEW VERSION !
  80.  
  81.  
  82. def is_inside(r, c):
  83.     return 0 <= r < SIZE and 0 <= c < SIZE
  84.  
  85.  
  86. def check_req_func(points):
  87.     if 100 <= points < 200:
  88.         return f"Good job! You scored {points} points, and you've won Football."
  89.     elif 200 <= points < 300:
  90.         return f"Good job! You scored {points} points, and you've won Teddy Bear."
  91.     elif points >= 300:
  92.         return f"Good job! You scored {points} points, and you've won Lego Construction Set."
  93.     else:
  94.         return f'Sorry! You need {100 - points} points more to win a prize.'
  95.  
  96.  
  97. def calculate_points_func(c):
  98.     result = 0
  99.     for cell in range(0, SIZE):
  100.         cur_shot = matrix[cell][c]
  101.         if not cur_shot.isalpha():
  102.             result += int(cur_shot)
  103.     return result
  104.  
  105.  
  106. SIZE = 6
  107. matrix = []
  108. target_B = []
  109. for _ in range(SIZE):
  110.     matrix.append(input().split())
  111.  
  112. total_sum = 0
  113. for _ in range(3):
  114.     row, col = eval(input())
  115.     if (row, col) not in target_B:
  116.         target_B.append((row, col))
  117.     else:
  118.         continue
  119.  
  120.     if is_inside(row, col):
  121.         current_shot = matrix[row][col]
  122.         if current_shot == 'B':
  123.             total_sum += calculate_points_func(col)
  124.  
  125. print(check_req_func(total_sum))
  126.  
  127.  
  128. ========================================================================================================
  129.  
  130. # 02. Ball in the Bucket
  131. # OLD VERSION
  132.  
  133.  
  134. def is_inside_func(r, c):
  135.     return 0 <= r < 6 and 0 <= c < 6
  136.  
  137.  
  138. def sum_func(current_col):
  139.     points = 0
  140.     for position in range(6):
  141.         if matrix[0 + position][current_col] != 'B':
  142.             points += int(matrix[0 + position][current_col])
  143.  
  144.     return points
  145.  
  146.  
  147. matrix = []
  148. target_down = []
  149.  
  150. for row_index in range(6):
  151.     matrix.append(input().split())
  152.  
  153. total_points = 0
  154.  
  155. for _ in range(3):
  156.     row, col = eval(input())
  157.     if is_inside_func(row, col):
  158.         if matrix[row][col] == 'B' and (row, col) not in target_down:
  159.             target_down.append((row, col))
  160.             total_points += sum_func(col)
  161.  
  162. toy_won = []
  163.  
  164. if 100 <= total_points < 200:
  165.     toy_won.append('Football')
  166. elif 200 <= total_points < 300:
  167.     toy_won.append('Teddy Bear')
  168. elif total_points >= 300:
  169.     toy_won.append('Lego Construction Set')
  170.  
  171. if toy_won:
  172.     print(f"Good job! You scored {total_points} points, and you've won {''.join(toy_won)}.")
  173. else:
  174.     print(f"Sorry! You need {100-total_points} points more to win a prize.")
  175.  
  176.    
  177. ------------------------------------------------------------------------------------------
  178. # 03. Shopping List
  179.  
  180.  
  181. def shopping_list(budget, **kwargs):
  182.     product_limit = 5
  183.     if budget < 100:
  184.         return f'You do not have enough budget.'
  185.    
  186.     total_product = ""
  187.     for product, details in kwargs.items():
  188.  
  189.         price = float(details[0])
  190.         count = float(details[1])
  191.        
  192.         result = price * count
  193.         if result <= budget and product_limit:
  194.             budget -= result
  195.             total_product += f'You bought {product} for {result:.2f} leva.\n'
  196.             product_limit -= 1
  197.  
  198.     return total_product
  199.  
  200.  
  201. ------------------------------------------------------------------------------------------
  202.  
  203.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement