Skip to content

Commit 9135586

Browse files
committed
Added Regular Exam
1 parent f869239 commit 9135586

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

Advanced/Regular Exam/# TODO.txt

Whitespace-only changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from collections import deque
2+
3+
textiles = deque(map(int, input().split()))
4+
medicaments = deque(map(int, input().split()))
5+
6+
owned_items = {
7+
"Patch": 0,
8+
"Bandage": 0,
9+
"MedKit": 0
10+
}
11+
12+
items = {
13+
"Patch": 30,
14+
"Bandage": 40,
15+
"MedKit": 100
16+
}
17+
18+
while textiles and medicaments:
19+
textile, medicament = textiles.popleft(), medicaments.pop()
20+
textile_medicaments_sum = textile + medicament
21+
22+
match = False
23+
24+
for item in items.keys():
25+
if textile_medicaments_sum == items[item]:
26+
owned_items[item] += 1
27+
match = True
28+
break
29+
30+
if not match:
31+
if textile_medicaments_sum > items["MedKit"]:
32+
owned_items["MedKit"] += 1
33+
if medicaments:
34+
medicament = medicaments.pop()
35+
medicament += textile_medicaments_sum - items["MedKit"]
36+
medicaments.append(medicament)
37+
38+
else:
39+
medicament += 10
40+
medicaments.append(medicament)
41+
42+
if medicaments and not textiles:
43+
print("Textiles are empty.")
44+
45+
elif textiles and not medicaments:
46+
print("Medicaments are empty.")
47+
48+
else:
49+
print("Textiles and medicaments are both empty.")
50+
51+
items_amount = sorted(owned_items.items(), key=lambda x: (-x[1], x[0]))
52+
53+
for item_amount in items_amount:
54+
item, amount = item_amount
55+
56+
if amount > 0:
57+
print(f"{item} - {amount}")
58+
59+
if medicaments:
60+
print(f"Medicaments left: {', '.join([str(num) for num in list(medicaments)[::-1]])}")
61+
62+
if textiles:
63+
print(f"Textiles left: {', '.join([str(num) for num in textiles])}")
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
rows, columns = list(map(int, input().split()))
2+
3+
furniture_obstacles = "O"
4+
empty = "-"
5+
opponents = "P"
6+
player = "B"
7+
player_coordinates = [0, 0]
8+
playground = []
9+
10+
for row in range(rows):
11+
cols = input().split()
12+
playground.append(cols)
13+
14+
if player in cols:
15+
player_coordinates = [len(playground)-1, cols.index(player)]
16+
playground[player_coordinates[0]][player_coordinates[1]] = empty
17+
18+
opponents_count = 0
19+
moves_count = 0
20+
21+
movement = input()
22+
while movement != "Finish" and opponents_count < 3:
23+
24+
if movement == "up":
25+
if 0 <= player_coordinates[0]-1 <= len(playground)-1:
26+
if playground[player_coordinates[0]-1][player_coordinates[1]] != furniture_obstacles:
27+
player_coordinates[0] -= 1
28+
moves_count += 1
29+
30+
elif movement == "down":
31+
if 0 <= player_coordinates[0]+1 <= len(playground) - 1:
32+
if playground[player_coordinates[0] + 1][player_coordinates[1]] != furniture_obstacles:
33+
player_coordinates[0] += 1
34+
moves_count += 1
35+
36+
elif movement == "left":
37+
if 0 <= player_coordinates[1]-1 <= len(playground[0]) - 1:
38+
if playground[player_coordinates[0]][player_coordinates[1]-1] != furniture_obstacles:
39+
player_coordinates[1] -= 1
40+
moves_count += 1
41+
42+
elif movement == "right":
43+
if 0 <= player_coordinates[1] + 1 <= len(playground[0]) - 1:
44+
if playground[player_coordinates[0]][player_coordinates[1]+1] != furniture_obstacles:
45+
player_coordinates[1] += 1
46+
moves_count += 1
47+
48+
if playground[player_coordinates[0]][player_coordinates[1]] == opponents:
49+
opponents_count += 1
50+
playground[player_coordinates[0]][player_coordinates[1]] = empty
51+
52+
movement = input()
53+
54+
print("Game over!")
55+
print(f"Touched opponents: {opponents_count} Moves made: {moves_count}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
def shop_from_grocery_list(budget, grocery_list: list, *products):
2+
bought_products = []
3+
4+
bought_all_products = True
5+
6+
for product_price in products:
7+
product, price = product_price
8+
9+
if budget >= price and product not in bought_products and product in grocery_list:
10+
budget -= price
11+
bought_products.append(product)
12+
13+
elif budget < price:
14+
bought_all_products = False
15+
break
16+
17+
if bought_all_products and not [x for x in grocery_list if x not in bought_products]:
18+
return f"Shopping is successful. Remaining budget: {budget:.2f}."
19+
20+
return f"You did not buy all the products. Missing products: {', '.join([product for product in [x for x in grocery_list if x not in bought_products]])}."
21+
22+
23+
''' TESTS '''
24+
# print(shop_from_grocery_list(
25+
# 100,
26+
# ["tomato", "cola"],
27+
# ("cola", 5.8),
28+
# ("tomato", 10.0),
29+
# ("tomato", 20.45),
30+
# ))
31+
# print()
32+
# print(shop_from_grocery_list(
33+
# 100,
34+
# ["tomato", "cola", "chips", "meat"],
35+
# ("cola", 5.8),
36+
# ("tomato", 10.0),
37+
# ("meat", 22),
38+
# ))
39+
# print()
40+
# print(shop_from_grocery_list(
41+
# 100,
42+
# ["tomato", "cola", "chips", "meat", "chocolate"],
43+
# ("cola", 15.8),
44+
# ("chocolate", 30),
45+
# ("tomato", 15.85),
46+
# ("chips", 50),
47+
# ("meat", 22.99),
48+
# ))

0 commit comments

Comments
 (0)