Nov-05-2019, 09:06 PM
I got the following code right now, but when I use the code. No matter which answer I fill in (even if it is the right answer), I get 'False, answer not detected. How is this possible? Why does this not work?
def Test (): import math b = 1 c = 5 a = math.sqrt(c-b) class Questions: def __init__(self, question, answer, answer2): self.question = question self.answer = answer self.answer2 = answer2 questions_list =[ ["Solve the equation x**2 + 1 = 5. \n \nRestriction: you can not use spaces in your answer. \nNote your answer in the following form if necessery: x=.. v √x v counter/denominator v x**2.", ("x=" + str(a) + "vx=-" + str(a)), ("x=-" + str(a) + "vx=" + str(a))], ] questions = [] for item in questions_list: questions.append(Questions(item[0],item[1],item[2])) def run_test(questions): for question in questions : print(questions.question) answer = input("\nAnswer: ") if answer == question.answer or answer == question.answer2: print("\nCorrect!\n") break if answer == ("x="+str(a)): print ("\nFalse, don’t forget that a negative x-value can also come out.\n\n") Test() break if answer == ("x=-"+str(a)): print ("\nFalse, don’t forget that a positive x-value can also come out.\n\n") Test() break if answer == ("x=√2") : print ("\nFalse, you haven taken the root twice of 5 - 1 = 4.\n\n") Test() break if answer == ("x=√2vx=-√2") : print ("\nFalse, you haven taken the root twice of 5 - 1 = 4.\n\n") Test() break if answer == ("x=-√2vx=√2") : print ("\nFalse, you haven taken the root twice of 5 - 1 = 4.\n\n") Test() break if answer == ("x=√4vx=-√4") : print ("\nFalse, you can work out your answer even further.\n\n") Test() break if answer == ("x=-√4vx=√4") : print ("\nFalse, you can work out your answer even further.\n\n") Test() break if answer == ("x=√4") : print ("\nFalse, you can work out your answer even further.\n\n") Test() break if answer == ("x=-√4") : print ("\nFalse, you can work out your answer even further.\n\n") Test() break else : print ("nFalse, answer not detected. \nTry again! \n\n") Test() run_test(questions)