Advertisement
DiYane

The pianist /new/

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