GeorgiLukanov87

03. The Pianist.01 100/100

Jul 7th, 2022 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # 03.The Pianist.
  2. # 01.Programming Fundamentals Final Exam Retake
  3. # https://judge.softuni.org/Contests/Practice/Index/2525#2
  4.  
  5.  
  6. n = int(input())
  7. data = {}
  8. for _ in range(n):
  9.     add_piece, add_composer, add_key = input().split("|")
  10.     data[add_piece] = [add_composer] + [add_key]
  11. command = input()
  12. while not command == 'Stop':
  13.     command = command.split("|")
  14.     if command[0] == 'Add':
  15.         piece = command[1]
  16.         composer = command[2]
  17.         key = command[3]
  18.         if piece in data:
  19.             print(f"{piece} is already in the collection!")
  20.         else:
  21.             data[piece] = [composer] + [key]
  22.             print(f"{piece} by {composer} in {key} added to the collection!")
  23.  
  24.     elif command[0] == 'Remove':
  25.         piece = command[1]
  26.         if piece not in data:
  27.             print(f"Invalid operation! {piece} does not exist in the collection.")
  28.         else:
  29.             print(f"Successfully removed {piece}!")
  30.             del data[piece]
  31.  
  32.     elif command[0] == 'ChangeKey':
  33.         piece = command[1]
  34.         new_key = command[2]
  35.         if piece not in data:
  36.             print(f"Invalid operation! {piece} does not exist in the collection.")
  37.         else:
  38.             data[piece][1] = new_key
  39.             print(f"Changed the key of {piece} to {new_key}!")
  40.  
  41.     command = input()
  42. for piece, value in data.items():
  43.     print(f"{piece} -> Composer: {value[0]}, Key: {value[1]}")
  44.  
Add Comment
Please, Sign In to add comment