python code to play a particular song with reference
Question: There is a file `1.mp3` in the location `/home/<username>/Music/`

Whatever name is given to a value of varible **`a`** , the code should
automatically search the specific folder and play that particular (number)
song

The code structure

    
    
    import pygame
    import time
    a=1                                                    # value assignment to <<a>> here
    pygame.init()
    pygame.mixer.music.load("/home/prabhat/Music/a.mp3")   # file to be opened
    pygame.mixer.music.play()
    time.sleep(1)
    


Answer: You need to use string formatting to get `a` in `'a.mp3'` be substituted with
the actual value.

You can do it either with

    
    
    pygame.mixer.music.load("/home/prabhat/Music/%s.mp3" % a)
    

or

    
    
    pygame.mixer.music.load("/home/prabhat/Music/{}.mp3".format(a))
    

See [string formatting
docs](https://docs.python.org/2/library/string.html#format-string-syntax) for
more info.

