Skip to content

Commit 9095648

Browse files
committed
Python Fundamentals - Final Exam Retake.
Problem: n°3.
1 parent 0ab5e38 commit 9095648

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
num_of_pieces = int(input())
2+
pieces = []
3+
composers = []
4+
keys = []
5+
6+
for el in range(num_of_pieces):
7+
current_piece = input()
8+
9+
piece, composer, key = current_piece.split("|")
10+
pieces.append(piece)
11+
composers.append(composer)
12+
keys.append(key)
13+
14+
command = input()
15+
while command != "Stop":
16+
current_command = command.split("|")
17+
action = current_command[0]
18+
19+
if action == "Add":
20+
piece, composer, key = current_command[1], current_command[2], current_command[3]
21+
if piece in pieces:
22+
print(f"{piece} is already in the collection!")
23+
else:
24+
print(f"{piece} by {composer} in {key} added to the collection!")
25+
pieces.append(piece)
26+
composers.append(composer)
27+
keys.append(key)
28+
29+
elif action == "Remove":
30+
piece = current_command[1]
31+
32+
if piece in pieces:
33+
piece_idx = pieces.index(piece)
34+
pieces.pop(piece_idx)
35+
composers.pop(piece_idx)
36+
keys.pop(piece_idx)
37+
38+
print(f"Successfully removed {piece}!")
39+
40+
else:
41+
print(f"Invalid operation! {piece} does not exist in the collection.")
42+
43+
elif action == "ChangeKey":
44+
piece, new_key = current_command[1], current_command[2]
45+
46+
if piece in pieces:
47+
piece_idx = pieces.index(piece)
48+
keys[piece_idx] = new_key
49+
50+
print(f"Changed the key of {piece} to {new_key}!")
51+
52+
else:
53+
print(f"Invalid operation! {piece} does not exist in the collection.")
54+
55+
command = input()
56+
57+
for idx in range(len(pieces)):
58+
current_piece = pieces[idx]
59+
current_composer = composers[idx]
60+
current_key = keys[idx]
61+
62+
print(f"{current_piece} -> Composer: {current_composer}, Key: {current_key}")

0 commit comments

Comments
 (0)