mardi 27 avril 2021

Python is not randomly giving a question and asks same question repeatedly

i'm having an issue with my program, a music quiz, where what is supposed to happen is that when getting it wrong and earning one point, the point system should reset and allow you to get 3 points for the next question. However, it will only give 1 point for all i get right first time after that. Also, for the questions, the first song question is asked randomly but the questions after the first are not random song questions. I'm not too sure if this makes any sense but hopefully the code will explain it better:

import csv
import random

with open("playlist.csv", "r") as input_file: #this is the name of my csv file
    csv_source = csv.DictReader(input_file)
    all_songs_and_artists = list(csv_source)

song_and_artist_chosen = random.choice(all_songs_and_artists)

song_words = song_and_artist_chosen["Songs"].split()
song_initials = "".join(item[0] for item in song_words)
initials_uppercase = song_initials.upper()

print("\n")

user_score = 0
asks = 0

while True:
    print("The artist is: " + song_artist_chosen["Artist"])
    print("and the initials are: " + initials_uppercase)
    user_guess = str(input("What's the song?"))
    if song_and_artist_chosen["Songs"].upper() == user_guess.upper(): 
       print("Correct!")
       if asks == 0: 
          user_score = user_score + 3
          print("You now have, ", user_score, "points")
          True
       elif asks == 1
           user_score = user_score + 1
           print("You have earned 1 point!")
           print("You now have ", user_score, "points")
           True
     else:
         asks = asks + 1
         if asks == 1:
            print("incorrect, you have one more try")
            user_guess = input("What's the song?")
            if song_and_artist_chosen["Songs"].upper() == user_guess.upper()
            user_score = user_score + 1
            print("Correct!")
            print("You now have ", user_score, "points")
            True
         else:
            print("------------------------")
            str(print("Unlucky, you lost, your score was ", + user_score))
            False
            quit()
            

Aucun commentaire:

Enregistrer un commentaire