Please, check these articles:
Keep in mind that in OnlineGDB you're running your code on a server, so if the output of a Python code is a command line program, the sound will (or not at all) be played on the server, which you'll never hear as only text is transferred to your browser.
If you're running the code on your local PC or the output of the Python code is a web page, then the sound instrument is going to run on your local PC and the above is not an issue.
Nice question. Well, there are lots of ways to do this.
The most common, easy and popular way which I also like and did is by using Playsound Library.
from playsound import playsoundplaysound('soundfile.mp3')
from playsound import playsound