My variable userAnswerList[]
takes the user's input, and I need to verify if the user has input other than A
, B
, C
, D
.
Here's my code below, and wondering how should I validate user's input between the range of (A
B
C
D
) and if not print the error message?
answerList = ["A","C","A","A","D","B","C","A","C","B","A","D","C","A","D","C","B","B","D","A"]
userAnswerList = []
correct = 0
incorrect = 0
def main():
for i in range(20):
i = i + 1
answer = input("Please Enter the answer for Question %d:" %i)
userAnswerList.append(answer)
numCorrect = [i for i in userAnswerList if i in answerList]
if len(numCorrect) > 15:
print("Congratulations You have passed the exam!")
elif len(numCorrect) < 15:
print("Failed....Please try again")
correct = len(numCorrect)
incorrect = 20 - correct
print("Correct Answers:",correct,"/ Incorrect Answers:",incorrect)
main()