I'm doing a music quiz for my OCR GCSE programming project. The aim of the python program is to generate a randomly chosen song from an array, display the initials of the song and also show the artist, then allow the user to guess the name of the song. The song array and the artist array are stored in separate external notepad files, and load in correctly, displaying the initials of the song and the artist. My problem is that, even if the user guesses the song name correctly, the program displays that it is incorrect and does not match the correct song name to the user input.
I have tried displaying the song name to make sure I am guessing the song name correctly, and have also tried copying the song name and copying it into the user input
import random
songlistfilecontents = open("songlist.txt", "r")
songlist = songlistfilecontents.readlines()
artistlistfilecontents = open("artistlist.txt", "r")
artistlist = artistlistfilecontents.readlines()
randomnumber = random.randint(0,11)
randomsong = songlist[randomnumber]
randomartist = artistlist [randomnumber]
initialsofsong = "".join(item[0].upper() for item in randomsong.split())
counter = 0
print("The songs' initials are " ,initialsofsong, " and the name of the
artist is " ,randomartist)
print (randomsong)
songnameguess = input("Guess the name of the song!")
counter = counter + 1
while songnameguess != randomsong:
songnameguess = input("Nope! Try again!")
counter = counter + 1
if counter >=3 and songnameguess != randomsong:
print ("Sorry, you've had two chances. Come back soon!")
elif songnameguess == randomsong:
print ("Well done!")
I expect the program to display "Well done!" if the user has not guessed the song incorrectly more than 3 times and guesses the answer correctly. However, the program never shows this and instead displays Nope! Try again and prompts for input for songnameguess until the user has guessed (incorrectly or correctly) three times, then prints Sorry, you've had two chances. Come back soon!