import pygame

def play_music(file_path):
    pygame.mixer.init()
    pygame.mixer.music.load(file_path)
    pygame.mixer.music.play()

def stop_music():
    pygame.mixer.music.stop()

if __name__ == "__main__":
    while True:
        print("1. play music")
        print("2. stop music")
        print("3. stop")
        choice = input("choose the action")

        if choice == "1":
            file_path = input("Enter the path to the music file: ")
            play_music(file_path)
        elif choice == "2":
            stop_music()
        elif choice == "3":
            break
        else:
            print("Invalid choice. Please try again.")

1. play music
2. stop music
3. stop
Invalid choice. Please try again.
1. play music
2. stop music
3. stop



---------------------------------------------------------------------------

error                                     Traceback (most recent call last)

/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb Cell 2 line 2
     <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=17'>18</a> if choice == "1":
     <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=18'>19</a>     file_path = input("Enter the path to the music file: ")
---> <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=19'>20</a>     play_music(file_path)
     <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=20'>21</a> elif choice == "2":
     <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=21'>22</a>     stop_music()


/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb Cell 2 line 5
      <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=2'>3</a> def play_music(file_path):
      <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=3'>4</a>     pygame.mixer.init()
----> <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=4'>5</a>     pygame.mixer.music.load(file_path)
      <a href='vscode-notebook-cell:/Users/alishahussain/vscode/student2/_notebooks/2023-11-05-musicplayer.ipynb#W0sZmlsZQ%3D%3D?line=5'>6</a>     pygame.mixer.music.play()


error: No file '' found in working directory '/Users/alishahussain/vscode/student2/_notebooks'.