Advertisement
KNenov96

03. The Pianist

Oct 10th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. number_of_pieces = int(input())
  2. pieces = {}
  3.  
  4. for piece in range(number_of_pieces):
  5.     information_about_pieces = input().split("|")
  6.     current_piece = information_about_pieces[0]
  7.     composer = information_about_pieces[1]
  8.     key = information_about_pieces[2]
  9.     pieces[current_piece] = [composer, key]
  10.  
  11. receiving_commands = True
  12. while receiving_commands:
  13.     command = input()
  14.     if command == "Stop":
  15.         receiving_commands = False
  16.         break
  17.  
  18.     command = command.split("|")
  19.     if command[0] == "Add":
  20.         add_piece = command[1]
  21.         add_composer = command[2]
  22.         add_key = command[3]
  23.         if add_piece not in pieces:
  24.             pieces[add_piece] = [add_composer, add_key]
  25.             print(f"{add_piece} by {add_composer} in {add_key} added to the collection!")
  26.         else:
  27.             print(f"{add_piece} is already in the collection!")
  28.  
  29.     elif command[0] == "Remove":
  30.         remove_piece = command[1]
  31.         if remove_piece in pieces:
  32.             del(pieces[remove_piece])
  33.             print(f"Successfully removed {remove_piece}!")
  34.         else:
  35.             print(f"Invalid operation! {remove_piece} does not exist in the collection.")
  36.  
  37.     elif command[0] == "ChangeKey":
  38.         change_piece = command[1]
  39.         new_key = command[2]
  40.         if change_piece in pieces:
  41.             pieces[change_piece][1] = new_key
  42.             print(f"Changed the key of {change_piece} to {new_key}!")
  43.         else:
  44.             print(f"Invalid operation! {change_piece} does not exist in the collection.")
  45.  
  46. for name in pieces:
  47.     composer = pieces[name][0]
  48.     key = pieces[name][1]
  49.     print(f"{name} -> Composer: {composer}, Key: {key}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement