Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Exam - 23 October 2021
- # https://judge.softuni.org/Contests/Practice/Index/3227#2
- # 01. Aladdin's Gifts
- # 02. Ball in the Bucket
- # 03. Shopping List
- ------------------------------------------------------------------------------------------
- # 01. Aladdin's Gifts
- from collections import deque
- def craft_gift_func(current_result):
- if 100 <= current_result <= 199:
- gifts['Gemstone'] += 1
- elif 200 <= current_result <= 299:
- gifts['Porcelain Sculpture'] += 1
- elif 300 <= current_result <= 399:
- gifts['Gold'] += 1
- elif 400 <= current_result <= 499:
- gifts['Diamond Jewellery'] += 1
- materials = deque([int(x) for x in input().split()])
- magic_values = deque([int(x) for x in input().split()])
- gifts = {'Diamond Jewellery': 0, 'Gemstone': 0, 'Gold': 0, 'Porcelain Sculpture': 0}
- while True:
- if not materials or not magic_values:
- break
- last_material = materials[-1]
- first_magic_value = magic_values[0]
- result = last_material + first_magic_value
- if result >= 100:
- craft_gift_func(result)
- elif result < 100:
- if result % 2 == 0:
- result = last_material * 2 + first_magic_value * 3
- else:
- result *= 2
- craft_gift_func(result)
- if result > 499:
- result /= 2
- craft_gift_func(result)
- materials.pop()
- magic_values.popleft()
- success = False
- if gifts['Gemstone'] > 0 and gifts['Porcelain Sculpture'] > 0:
- success = True
- if gifts['Gold'] > 0 and gifts['Diamond Jewellery'] > 0:
- success = True
- if success:
- print("The wedding presents are made!")
- else:
- print("Aladdin does not have enough wedding presents.")
- if materials:
- print(f'Materials left: {", ".join(str(m) for m in materials)}')
- if magic_values:
- print(f"Magic left: {', '.join(str(v) for v in magic_values)}")
- for name, count in gifts.items():
- if count:
- print(f'{name}: {count}')
- ------------------------------------------------------------------------------------------
- # 02. Ball in the Bucket
- # NEW VERSION !
- def is_inside(r, c):
- return 0 <= r < SIZE and 0 <= c < SIZE
- def check_req_func(points):
- if 100 <= points < 200:
- return f"Good job! You scored {points} points, and you've won Football."
- elif 200 <= points < 300:
- return f"Good job! You scored {points} points, and you've won Teddy Bear."
- elif points >= 300:
- return f"Good job! You scored {points} points, and you've won Lego Construction Set."
- else:
- return f'Sorry! You need {100 - points} points more to win a prize.'
- def calculate_points_func(c):
- result = 0
- for cell in range(0, SIZE):
- cur_shot = matrix[cell][c]
- if not cur_shot.isalpha():
- result += int(cur_shot)
- return result
- SIZE = 6
- matrix = []
- target_B = []
- for _ in range(SIZE):
- matrix.append(input().split())
- total_sum = 0
- for _ in range(3):
- row, col = eval(input())
- if (row, col) not in target_B:
- target_B.append((row, col))
- else:
- continue
- if is_inside(row, col):
- current_shot = matrix[row][col]
- if current_shot == 'B':
- total_sum += calculate_points_func(col)
- print(check_req_func(total_sum))
- ========================================================================================================
- # 02. Ball in the Bucket
- # OLD VERSION
- def is_inside_func(r, c):
- return 0 <= r < 6 and 0 <= c < 6
- def sum_func(current_col):
- points = 0
- for position in range(6):
- if matrix[0 + position][current_col] != 'B':
- points += int(matrix[0 + position][current_col])
- return points
- matrix = []
- target_down = []
- for row_index in range(6):
- matrix.append(input().split())
- total_points = 0
- for _ in range(3):
- row, col = eval(input())
- if is_inside_func(row, col):
- if matrix[row][col] == 'B' and (row, col) not in target_down:
- target_down.append((row, col))
- total_points += sum_func(col)
- toy_won = []
- if 100 <= total_points < 200:
- toy_won.append('Football')
- elif 200 <= total_points < 300:
- toy_won.append('Teddy Bear')
- elif total_points >= 300:
- toy_won.append('Lego Construction Set')
- if toy_won:
- print(f"Good job! You scored {total_points} points, and you've won {''.join(toy_won)}.")
- else:
- print(f"Sorry! You need {100-total_points} points more to win a prize.")
- ------------------------------------------------------------------------------------------
- # 03. Shopping List
- def shopping_list(budget, **kwargs):
- product_limit = 5
- if budget < 100:
- return f'You do not have enough budget.'
- total_product = ""
- for product, details in kwargs.items():
- price = float(details[0])
- count = float(details[1])
- result = price * count
- if result <= budget and product_limit:
- budget -= result
- total_product += f'You bought {product} for {result:.2f} leva.\n'
- product_limit -= 1
- return total_product
- ------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement