Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stuck on Music Quiz
#1
Stuck on Music Quiz Game

Hello, I am doing an assignment which is a Music Quiz Game, I have completed The Login, Menu, Rules and now need to do the game itself, but I can't figure out where to start.
I have all the songs and artists on a seperate Document, seperated by the Character "|" I have also made the code for splitting the songs and artists from each other:
def random_line(SongsArtists):
    line = next(SongsArtists.txt)
    for num, SongsArtists.txt in enumerate(SongsArtists.txt, 2):
      if random.randrange(num): continue
      line = line.strip().split("|")
    return line
I am stuck on making it pick a a random line from the artist/song list, and making it show you the artist and the song, and then you type the song as your answer. There will be another part but I will do this myself.
Any help would be appreciated. Pray
Reply
#2
Look at random.choice(). Python docs for Random
Reply
#3
Thanks, but what I need is a user input scenario where I have some guesses and it will go to the next question if correct (If you get what I'm saying) not a multiple choice thing, Apologies.
Reply
#4
I don't think you went to the link and read. Random.choice is not for multiple choice.
import random

with open("SongArtists.txt","r") as file:
    lines = file.readlines()

chosen_line = random.choice(lines)
#Now split.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020