Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have created a juke box and have imported a random module. The user picks what

ID: 3588277 • Letter: I

Question

I have created a juke box and have imported a random module. The user picks what genre of music they want(in this particular portion of code it is c = country) then they choose 1-3 of which song they want. I want the fourth option to be a random song. How do I do this?

if genre == "c":
       
        print(" Below is a list of country songs. Please choose which number you would like to play.")
       
        print(" 1. " + songList[0])

        print("2. " + songList[1])

        song = input("3. " + songList[2] + " ")


        if song == "1":

            webbrowser.open('https://www.youtube.com/watch?v=rB7ONnfIjaI')

        elif song == "2":

            webbrowser.open('https://www.youtube.com/watch?v=pl4c0kZUm2M')

        elif song == "3":

            webbrowser.open('https://www.youtube.com/watch?v=vNVguvNE7qc')

        elif song == "4":

            ?????????????????????????????

        else:

            print(" Sorry " + song + " is not one of the choices.")  
                 

                 

Explanation / Answer

Put above code in the place of ?????????????????????????????.

if genre == "c":

print(" Below is a list of country songs. Please choose which number you would like to play.")

print(" 1. " + songList[0])
print("2. " + songList[1])
song = input("3. " + songList[2] + " ")

if song == "1":
webbrowser.open('https://www.youtube.com/watch?v=rB7ONnfIjaI')
elif song == "2":
webbrowser.open('https://www.youtube.com/watch?v=pl4c0kZUm2M')
elif song == "3":
webbrowser.open('https://www.youtube.com/watch?v=vNVguvNE7qc')
elif song == "4":
           import random
           a = ['https://www.youtube.com/watch?v=rB7ONnfIjaI', 'https://www.youtube.com/watch?v=pl4c0kZUm2M', 'https://www.youtube.com/watch?v=vNVguvNE7qc']
           r = random.randint(0,2)
           webbrowser.open(a[r])
else:
print(" Sorry " + song + " is not one of the choices.")

import random
a = ['https://www.youtube.com/watch?v=rB7ONnfIjaI', 'https://www.youtube.com/watch?v=pl4c0kZUm2M', 'https://www.youtube.com/watch?v=vNVguvNE7qc']
r = random.randint(0,2)
webbrowser.open(a[r])
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote