0
def QandA():

    s_easy = open("Science (Easy).txt","r")
    score = 0
    for x in range (5):
        print(s_easy.readline())
        answer = s_easy.readline()
        useranswer = input("Enter your answer as an uppercase: ") 
        if useranswer.isspace()or useranswer.islower():
            while useranswer.isspace() or useranswer.islower(): 
                print("You must enter a valid letter.")
                useranswer = input("Enter your answer as an uppercase: ")
            while useranswer != "A" or useranswer != "B":
                print("You must enter a valid letter.")
                useranswer = input("Enter your answer as an uppercase: ")
            if answer == useranswer:
                score = score + 1
            else:
                score = score
        elif answer == useranswer:
            score = score + 1
        else:
            score = score
    print(score)

I need the while loop to ask the user to input their answer again if the useranswer is not uppercase, a space or not "A" or "B". I also need the score to increase by increments of 1 with every correct answer and to be printed at the end. I have tried to include the score, but it is just not working for me.

N.Kennedy
  • 1
  • 1

1 Answers1

0

You need to change the or to and:

while useranswer != "A" and useranswer != "B":
    #code

This is because you only wnat to prompt them again if the input isn't A and it isn't B.

gommb
  • 1,121
  • 1
  • 7
  • 21