Skip to content

Commit 8e85aca

Browse files
authored
Added Exam Preparation - Lab (#37)
2 parents 2c3da6d + d22a882 commit 8e85aca

File tree

6 files changed

+189
-2
lines changed

6 files changed

+189
-2
lines changed

Advanced/Exam Preparation/# TODO.txt

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from collections import deque
2+
3+
4+
def conquer_peaks(food, stamina):
5+
peaks = {"Vihren": 80, "Kutelo": 90, "Banski Suhodol": 100, "Polezhan": 60, "Kamenitza": 70}
6+
conquered_peaks = []
7+
8+
day = 0
9+
10+
while len(food) and len(stamina):
11+
12+
if day == 7:
13+
break
14+
15+
if not len(peaks):
16+
break
17+
18+
day += 1
19+
daily_energy = food.pop() + stamina.popleft()
20+
current_peak = list(peaks.keys())[0]
21+
22+
if daily_energy >= peaks[current_peak]:
23+
conquered_peaks.append(current_peak)
24+
del peaks[current_peak]
25+
26+
return conquered_peaks
27+
28+
29+
food_portions = deque(map(int, input().split(", ")))
30+
stamina = deque(map(int, input().split(", ")))
31+
32+
conquered_peaks = conquer_peaks(food_portions, stamina)
33+
34+
if len(conquered_peaks) == 5:
35+
print("Alex did it! He climbed all top five Pirin peaks in one week -> @FIVEinAWEEK")
36+
37+
else:
38+
print("Alex failed! He has to organize his journey better next time -> @PIRINWINS")
39+
40+
if conquered_peaks:
41+
print("Conquered peaks:")
42+
[print(peak) for peak in conquered_peaks]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
def get_field(size):
2+
racer_number = input()
3+
up_tunnel_entry, down_tunnel_entry = [], []
4+
matrix = []
5+
6+
for row in range(size):
7+
columns = input().split()
8+
matrix.append(columns)
9+
10+
if columns.count("T") == 2:
11+
t_number = 0
12+
for index, col in enumerate(columns):
13+
if col == "T" and t_number == 0:
14+
t_number += 1
15+
up_tunnel_entry = (len(matrix)-1, index)
16+
17+
elif col == "T" and t_number == 1:
18+
down_tunnel_entry = (len(matrix)-1, index)
19+
20+
elif columns.count("T") == 1:
21+
22+
if not up_tunnel_entry:
23+
up_tunnel_entry = (len(matrix)-1, columns.index("T"))
24+
25+
else:
26+
down_tunnel_entry = (len(matrix)-1, columns.index("T"))
27+
28+
return racer_number, up_tunnel_entry, down_tunnel_entry, matrix
29+
30+
31+
def race(matrix, top_tunnel_entry, bottom_tunnel_entry):
32+
racer_coordinates = [0, 0]
33+
kilometers = 0
34+
35+
movement = input()
36+
while movement != "End":
37+
38+
if movement == "up":
39+
racer_coordinates[0] -= 1
40+
41+
elif movement == "down":
42+
racer_coordinates[0] += 1
43+
44+
elif movement == "left":
45+
racer_coordinates[1] -= 1
46+
47+
elif movement == "right":
48+
racer_coordinates[1] += 1
49+
50+
if matrix[racer_coordinates[0]][racer_coordinates[1]] == "T":
51+
kilometers += 20
52+
53+
if tuple(racer_coordinates) == top_tunnel_entry:
54+
racer_coordinates = list(bottom_tunnel_entry)
55+
56+
elif tuple(racer_coordinates) == bottom_tunnel_entry:
57+
racer_coordinates = list(top_tunnel_entry)
58+
59+
matrix[top_tunnel_entry[0]][top_tunnel_entry[1]] = "."
60+
matrix[bottom_tunnel_entry[0]][bottom_tunnel_entry[1]] = "."
61+
62+
kilometers += 10
63+
64+
if matrix[racer_coordinates[0]][racer_coordinates[1]] == "F":
65+
matrix[racer_coordinates[0]][racer_coordinates[1]] = "C"
66+
return [True, kilometers]
67+
68+
movement = input()
69+
70+
matrix[racer_coordinates[0]][racer_coordinates[1]] = "C"
71+
return [False, kilometers]
72+
73+
74+
matrix_size = int(input())
75+
racer, top_tunnel, bottom_tunnel, matrix = get_field(matrix_size)
76+
77+
finished, kilometers = race(matrix, top_tunnel, bottom_tunnel)
78+
79+
if finished:
80+
print(f"Racing car {racer} finished stage!")
81+
82+
else:
83+
print(f"Racing car {racer} DNF.")
84+
85+
86+
print(f"Distance covered {kilometers} km.")
87+
[print(''.join(column)) for column in matrix]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
def shopping_cart(*products):
2+
meals = {"Soup": 3, "Pizza": 4, "Dessert": 2}
3+
meal_products = {"Soup": [], "Pizza": [], "Dessert": []}
4+
5+
for product in products:
6+
7+
if product == "Stop":
8+
break
9+
10+
if product[0] in meals.keys():
11+
if meals[product[0]] > 0:
12+
meals[product[0]] -= 1
13+
if product[1] not in meal_products[product[0]]:
14+
meal_products[product[0]].append(product[1])
15+
16+
sorted_meals = sorted(meal_products.items(), key=lambda x: (-len(x[1]), x[0]))
17+
18+
checker = 0
19+
for meal in sorted_meals:
20+
if not meal[1]:
21+
checker += 1
22+
23+
if checker == 3:
24+
return "No products in the cart!"
25+
26+
output = ''
27+
28+
for list_products in sorted_meals:
29+
sorted_products = '\n'.join([f' - {product}' for product in sorted(list_products[1])])
30+
output += f"{list_products[0]}:\n{sorted_products}\n"
31+
32+
return output # output[:-1] in case you don't want the last line.
33+
34+
35+
''' TESTS '''
36+
# print(shopping_cart(
37+
# ('Pizza', 'ham'),
38+
# ('Soup', 'carrots'),
39+
# ('Pizza', 'cheese'),
40+
# ('Pizza', 'flour'),
41+
# ('Dessert', 'milk'),
42+
# ('Pizza', 'mushrooms'),
43+
# ('Pizza', 'tomatoes'),
44+
# 'Stop',
45+
# ))
46+
# print()
47+
# print(shopping_cart(
48+
# ('Pizza', 'ham'),
49+
# ('Dessert', 'milk'),
50+
# ('Pizza', 'ham'),
51+
# 'Stop',
52+
# ))
53+
# print()
54+
# print(shopping_cart(
55+
# 'Stop',
56+
# ('Pizza', 'ham'),
57+
# ('Pizza', 'mushrooms'),
58+
# ))

Advanced/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
| ----- |
4242
| Exams |
4343
| ----- |
44-
| Exam Preparation |
44+
| <a href="Exam Preparation">Exam Preparation</a> |
4545
| Regular Exam |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Course Exercise Lecturer - **[Diyan Kalaydzhiev](https://github.com/DiyanKalaydz
1515
| <a href="Advanced/5.File Handling">File Handling</a> | Static and Class Methods |
1616
| <a href="Advanced/6.Workshop">Workshop</a> | Polymorphism and Abstraction |
1717
| <a href="Advanced/7.Modules">Modules</a> | SOLID |
18-
| Exam Preparation | Iterators and Generators |
18+
| <a href="Advanced/Exam Preparation">Exam Preparation</a> | Iterators and Generators |
1919
| Regular Exam | Decorators |
2020
| | Testing |
2121
| | Design Patterns |

0 commit comments

Comments
 (0)