Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Display the problem, stored in the parameter prob_spec in the IDLE shell
- Grab the answer and strip the answer of whitespace to make processing easier
- Compare the userβs solution to the correct one (stored in the parameter prob_sol)
- If they got it right, tell them a happy message and return True
- Otherwise tell them to try again and the number of tries they have left
- If the number of tries exceeds the max_attempts then tell them they are out of tries AND what the actual answer was, and return False
- from random import randint
- def parse_line( prob_info ):
- list1 = []
- prob_info.find("<problem>")
- prob_info.find("<answer>")
- list1.append("<problem>")
- list1.append("<answer>")
- return list1
- def read_file():
- index1 = input("What is the name of the file containing your practice problems: ")
- testfile = (index1, "r")
- for line in testfile:
- parse_line("probs.txt")
- list_of_probs = []
- list_of_probs.append(list1)
- return list_of_probs
- def incorrect_feedback(list_of_msg):
- pos = randint(0, len(list_of_msg)- 1)
- return
- def test_student(incorrect_msg, max_attempts, prob_spec, prob_sol):
- num_of_attempts = 0
- print(prob_spec)
- index2 = input("Your answer: ")
- sol.strip()
- if sol == prob_sol:
- print("Great job!")
- return True
- else:
- print(message, "You have", max_attempts - 1, "tries left.")
- if max_attempts == 0:
- print("Out of tries for this one - moving on. The answer was", prob_sol)
- return False
- index = input("What is your name? ")
- print("Welcome", index, "to the math cognition tutor. You will practice some standard problems.")
- index3 = int(input("How many attempts do you want to give yourself per question? "))
- num_passed = 0
- read_file()
- for ele in list_of_probs:
- test_student(incorrect_msg, max_attempts, prob_spec, prob_sol)
- if test_student == True:
- num_passed = num_passed + 1
- print("Considering your final solutions, you got", num_passed, "problems correct out of 3")
Add Comment
Please, Sign In to add comment