Skip to content

Commit 6f4e0f0

Browse files
committed
Added Exam Preparation - Exercise
1 parent d22a882 commit 6f4e0f0

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from collections import deque
2+
3+
bowls_of_ramen = deque(map(int, input().split(", ")))
4+
customers = deque(map(int, input().split(", ")))
5+
6+
while bowls_of_ramen and customers:
7+
ramen, customer = bowls_of_ramen.pop(), customers.popleft()
8+
9+
if ramen > customer:
10+
ramen -= customer
11+
bowls_of_ramen.append(ramen)
12+
13+
elif customer > ramen:
14+
customer -= ramen
15+
customers.appendleft(customer)
16+
17+
18+
if not customers:
19+
print("Great job! You served all the customers.")
20+
21+
if bowls_of_ramen:
22+
print(f"Bowls of ramen left: {', '.join([str(num) for num in bowls_of_ramen])}")
23+
24+
elif customers:
25+
print("Out of ramen! You didn't manage to serve all customers.")
26+
print(f"Customers left: {', '.join([str(num) for num in customers])}")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
size = int(input())
2+
3+
battle_field = []
4+
submarine = [0, 0]
5+
6+
for row in range(size):
7+
columns = [char for char in input()]
8+
battle_field.append(columns)
9+
10+
if 'S' in columns:
11+
submarine = [len(battle_field)-1, columns.index('S')]
12+
battle_field[submarine[0]][submarine[1]] = '-'
13+
14+
15+
naval_mines = 0
16+
cruisers = 0
17+
18+
while True:
19+
movement = input()
20+
21+
if movement == "up":
22+
submarine[0] -= 1
23+
24+
elif movement == "down":
25+
submarine[0] += 1
26+
27+
elif movement == "left":
28+
submarine[1] -= 1
29+
30+
elif movement == "right":
31+
submarine[1] += 1
32+
33+
if battle_field[submarine[0]][submarine[1]] == "*":
34+
naval_mines += 1
35+
battle_field[submarine[0]][submarine[1]] = '-'
36+
37+
if naval_mines == 3:
38+
print(f"Mission failed, U-9 disappeared! Last known coordinates [{submarine[0]}, {submarine[1]}]!")
39+
break
40+
41+
elif battle_field[submarine[0]][submarine[1]] == "C":
42+
cruisers += 1
43+
battle_field[submarine[0]][submarine[1]] = '-'
44+
45+
if cruisers == 3:
46+
print("Mission accomplished, U-9 has destroyed all battle cruisers of the enemy!")
47+
break
48+
49+
battle_field[submarine[0]][submarine[1]] = 'S'
50+
[print(''.join(row)) for row in battle_field]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
def forecast(*locations):
2+
3+
weathers = {
4+
"Sunny": [],
5+
"Cloudy": [],
6+
"Rainy": []
7+
}
8+
9+
for location_weather in locations:
10+
location, weather = location_weather
11+
try:
12+
weathers[weather].append(location)
13+
except KeyError:
14+
continue
15+
16+
result = []
17+
for weather, locs in weathers.items():
18+
locs = sorted(locs)
19+
for loc in locs:
20+
result.append(f"{loc} - {weather}")
21+
22+
return '\n'.join(result)
23+
24+
25+
''' TESTS '''
26+
# print(forecast(
27+
# ("Sofia", "Sunny"),
28+
# ("London", "Cloudy"),
29+
# ("New York", "Sunny")))
30+
# print()
31+
# print(forecast(
32+
# ("Beijing", "Sunny"),
33+
# ("Hong Kong", "Rainy"),
34+
# ("Tokyo", "Sunny"),
35+
# ("Sofia", "Cloudy"),
36+
# ("Peru", "Sunny"),
37+
# ("Florence", "Cloudy"),
38+
# ("Bourgas", "Sunny")))
39+
# print()
40+
# print(forecast(
41+
# ("Tokyo", "Rainy"),
42+
# ("Sofia", "Rainy")))

0 commit comments

Comments
 (0)