Python CodeHS Question
Hey guys! I’m currently writing a code that gives song suggestions if someone simply presses a key, but I’m stuck on how to use the list I made in my code, which is my_songs[ blah, blah, blah]. Can anybody please help me? Thank you!
One way to do this is to create a function which is called on key press the function can look like this:
import random my_songs = [song1, song2, song3] get_song = lambda: random.choice(my_songs)
Do you want a random item from the list?
import random songs = ['bla bla bla', 'bla bla', 'bla bla bla bla'] while True: input("Press enter to generate a song!") print(random.choice(songs))
Or just select them from the list, with their index number
songSelected = songs[index_number]