Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def parse_line(prob_info):
- list1 = prob_info.strip("<>").split("> <")
- return list1
- def read_file(file_name):
- list_of_probs = []
- prob_info = open(file_name, 'r')
- problems = prob_info.read().splitlines()
- for line in problems:
- question = parse_line(line)
- list_of_probs.append(question)
- return list_of_probs
- def incorrect_feedback(list_of_msg):
- pos = randint(0, len(list_of_msg) - 1)
- return list_of_msg[pos]
- def test_student(incorrect_msg_list, max_attempts, prob_spec, prob_sol):
- attempts = 0
- while attempts < max_attempts:
- print prob_spec
- user_answer = raw_input('What is your answer? ').strip()
- if user_answer == prob_sol:
- print "You got it right!"
- return True
- else:
- print incorrect_feedback(incorrect_msg_list)
- attempts += 1
- print attempts
- print max_attempts
- print "You're all out of attempts!"
- return False
- your_name = raw_input('What is your name? ')
- print 'Welcome ' + your_name + ' to the math cognition tutor. You will practice some standard problems.'
- max_attempts = int(raw_input('How many attempts do you want to give yourself per question? '))
- file_name = raw_input('What is the name of the file containing your practice problems: ')
- incorrect_msg = ["Try again!", "Hmm - not quite", "Oops - a typo maybe?"]
- numpassed = 0
- list_of_probs = read_file(file_name)
- print list_of_probs
- for problem in list_of_probs:
- test_student(incorrect_msg, max_attempts, problem[0], problem[1])
- if test_student == True:
- numpassed += 1
- print "You got " + str(numpassed) + " questions right!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement