Why is the correct answer printing both score = 3 and score = 1?

77 views Asked by At

When you enter the correct answer ("Bad Guy"), it prints score = 3 and score = 1 at the same time? How do I prevent this so after getting it right in one attempt, it displays (and saves) score = 3, and after getting it right on the second attempt, it displays (and saves) the score as 1? By the way, if the player guesses correctly the first time, they gain 3 points.If they get it wrong, they try again. If they guess correctly the second time, they only gain 1 point. If they still get it wrong, the game ends. Please explain what's wrong and try to fix this problem please.

Here's the code I'm using for this:

score = 0
print("Round 1:")
with open('songs.txt') as songs_list:
song_name = songs_list.readline()
answer = input("What is the song name? " + song_name)
if answer == "Bad Guy":
    score+=3
    print("Correct! Score = 3")   
else:
    print("Incorrect! Try again.")
    answer = input("What is the song name? " + song_name)
if answer == "Bad Guy":
    score +=1
    print("Correct! Score = 1")
else:
    print("Incorrect! Unlucky, you lost. I hope you enjoyed playing!")
    import sys
    sys.exit()
2

There are 2 answers

0
Prune On BEST ANSWER

Your most immediate problem is that you never print score. Your only reports to the user are the literal strings Score = 3 and Score = 1. You'll need something like

print("you got 3 more points; new score =", score)
0
Dan On

You should indent the second set of if-else statements. This means the second set will only occur if the first answer is wrong.

score = 0
print("Round 1:")
with open('songs.txt') as songs_list:
song_name = songs_list.readline()
answer = input("What is the song name? " + song_name)
if answer == "Bad Guy":
    score+=3
    print("Correct! Score = 3")   
else:
    print("Incorrect! Try again.")
    answer = input("What is the song name? " + song_name)
    if answer == "Bad Guy":
        score +=1
        print("Correct! Score = 1")
    else:
        print("Incorrect! Unlucky, you lost. I hope you enjoyed playing!")
        import sys
        sys.exit()