Skip to content

Commit 20a1f33

Browse files
authored
Added Exam Preparation/Python Advanced Exam - 27 June 2020 (#39)
2 parents 903bb13 + f869239 commit 20a1f33

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from collections import deque
2+
3+
bomb_effects = deque(map(int, input().split(", ")))
4+
bomb_casings = deque(map(int, input().split(", ")))
5+
6+
bombs_pouch = {
7+
"Cherry Bombs": 0,
8+
"Datura Bombs": 0,
9+
"Smoke Decoy Bombs": 0
10+
}
11+
12+
bombs = {
13+
"Cherry Bombs": 60,
14+
"Datura Bombs": 40,
15+
"Smoke Decoy Bombs": 120
16+
}
17+
18+
while bomb_effects and bomb_casings:
19+
20+
if len([bomb for bomb in bombs_pouch.keys() if bombs_pouch[bomb] >= 3]) == 3:
21+
break
22+
23+
effect, casing = bomb_effects.popleft(), bomb_casings.pop()
24+
25+
while effect >= 0 and casing >= 0:
26+
27+
have_bomb = False
28+
29+
for bomb in bombs:
30+
31+
if effect + casing == bombs[bomb]:
32+
33+
bombs_pouch[bomb] += 1
34+
have_bomb = True
35+
36+
break
37+
38+
if have_bomb:
39+
break
40+
41+
casing -= 5
42+
43+
if len([bomb for bomb in bombs_pouch.keys() if bombs_pouch[bomb] >= 3]) == 3:
44+
print("Bene! You have successfully filled the bomb pouch!")
45+
46+
else:
47+
print("You don't have enough materials to fill the bomb pouch.")
48+
49+
if bomb_effects:
50+
print(f"Bomb Effects: {', '.join([str(eff) for eff in bomb_effects])}")
51+
52+
else:
53+
print("Bomb Effects: empty")
54+
55+
if bomb_casings:
56+
print(f"Bomb Casings: {', '.join([str(cass) for cass in bomb_casings])}")
57+
58+
else:
59+
print("Bomb Casings: empty")
60+
61+
[print(f"{bomb}: {amount}") for bomb, amount in bombs_pouch.items()]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
size = int(input())
2+
3+
food = '*'
4+
lair = "B"
5+
snake = "S"
6+
trail = '.'
7+
top_lair, bottom_lair = [], []
8+
snake_coordinates = [0, 0]
9+
10+
food_eaten = 0
11+
12+
snake_territory = []
13+
14+
for row in range(size):
15+
columns = [char for char in input()]
16+
snake_territory.append(columns)
17+
18+
if snake in columns:
19+
snake_coordinates = [len(snake_territory)-1, columns.index(snake)]
20+
snake_territory[snake_coordinates[0]][snake_coordinates[1]] = trail
21+
22+
if columns.count(lair) == 2:
23+
turn = 0
24+
for index in range(len(columns)):
25+
if turn == 0:
26+
if columns[index] == lair:
27+
top_lair = [len(snake_territory)-1, index]
28+
turn += 1
29+
30+
elif columns[index] == lair and turn == 1:
31+
bottom_lair = [len(snake_territory)-1, index]
32+
break
33+
34+
elif lair in columns:
35+
if top_lair:
36+
bottom_lair = [len(snake_territory)-1, columns.index(lair)]
37+
continue
38+
top_lair = [len(snake_territory)-1, columns.index(lair)]
39+
40+
snake_out_of_territory = False
41+
42+
while food_eaten < 10:
43+
movement = input()
44+
45+
try:
46+
47+
if movement == "up":
48+
snake_coordinates[0] -= 1
49+
50+
elif movement == "down":
51+
snake_coordinates[0] += 1
52+
53+
elif movement == "left":
54+
snake_coordinates[1] -= 1
55+
56+
elif movement == "right":
57+
snake_coordinates[1] += 1
58+
59+
if snake_territory[snake_coordinates[0]][snake_coordinates[1]] == food:
60+
food_eaten += 1
61+
62+
elif snake_territory[snake_coordinates[0]][snake_coordinates[1]] == lair:
63+
snake_territory[snake_coordinates[0]][snake_coordinates[1]] = trail
64+
65+
if snake_coordinates == top_lair:
66+
snake_coordinates = bottom_lair
67+
68+
else:
69+
snake_coordinates = top_lair
70+
71+
snake_territory[snake_coordinates[0]][snake_coordinates[1]] = trail
72+
73+
except IndexError:
74+
print("Game over!")
75+
snake_out_of_territory = True
76+
break
77+
78+
if food_eaten >= 10:
79+
print("You won! You fed the snake.")
80+
81+
print(f"Food eaten: {food_eaten}")
82+
83+
if not snake_out_of_territory:
84+
snake_territory[snake_coordinates[0]][snake_coordinates[1]] = snake
85+
86+
[print(''.join(row)) for row in snake_territory]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def list_manipulator(numbers: list, *args):
2+
if args[0] == "add":
3+
if args[1] == "beginning":
4+
numbers = list(args[2:]) + numbers
5+
6+
elif args[1] == "end":
7+
numbers = numbers + list(args[2:])
8+
9+
elif args[0] == "remove":
10+
if args[1] == "beginning":
11+
if len(args) == 3:
12+
for i in range(args[2]):
13+
if numbers:
14+
numbers = numbers[1:]
15+
else:
16+
numbers = numbers[1:]
17+
18+
elif args[1] == "end":
19+
if len(args) == 3:
20+
for i in range(args[2]):
21+
if numbers:
22+
numbers = numbers[:-1]
23+
else:
24+
numbers = numbers[:-1]
25+
26+
return numbers
27+
28+
29+
''' TESTS '''
30+
# print(list_manipulator([1,2,3], "remove", "end"))
31+
# print(list_manipulator([1,2,3], "remove", "beginning"))
32+
# print(list_manipulator([1,2,3], "add", "beginning", 20))
33+
# print(list_manipulator([1,2,3], "add", "end", 30))
34+
# print(list_manipulator([1,2,3], "remove", "end", 2))
35+
# print(list_manipulator([1,2,3], "remove", "beginning", 2))
36+
# print(list_manipulator([1,2,3], "add", "beginning", 20, 30, 40))
37+
# print(list_manipulator([1,2,3], "add", "end", 30, 40, 50))

0 commit comments

Comments
 (0)