Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. from random import randint
  2.  
  3. def parse_line(prob_info):
  4. list1 = prob_info.strip("<>").split("> <")
  5. return list1
  6.  
  7. def read_file(file_name):
  8. list_of_probs = []
  9. prob_info = open(file_name, 'r')
  10. problems = prob_info.read().splitlines()
  11. for line in problems:
  12. question = parse_line(line)
  13. list_of_probs.append(question)
  14. return list_of_probs
  15.  
  16. def incorrect_feedback(list_of_msg):
  17. pos = randint(0, len(list_of_msg) - 1)
  18. return list_of_msg[pos]
  19.  
  20. def test_student(incorrect_msg_list, max_attempts, prob_spec, prob_sol):
  21. attempts = 0
  22. while attempts < max_attempts:
  23. print prob_spec
  24. user_answer = raw_input('What is your answer? ').strip()
  25. if user_answer == prob_sol:
  26. print "You got it right!"
  27. return True
  28. else:
  29. print incorrect_feedback(incorrect_msg_list)
  30. attempts += 1
  31. print attempts
  32. print max_attempts
  33. print "You're all out of attempts!"
  34. return False
  35.  
  36. your_name = raw_input('What is your name? ')
  37. print 'Welcome ' + your_name + ' to the math cognition tutor. You will practice some standard problems.'
  38. max_attempts = int(raw_input('How many attempts do you want to give yourself per question? '))
  39. file_name = raw_input('What is the name of the file containing your practice problems: ')
  40. incorrect_msg = ["Try again!", "Hmm - not quite", "Oops - a typo maybe?"]
  41. numpassed = 0
  42.  
  43. list_of_probs = read_file(file_name)
  44. print list_of_probs
  45. for problem in list_of_probs:
  46. test_student(incorrect_msg, max_attempts, problem[0], problem[1])
  47. if test_student == True:
  48. numpassed += 1
  49. print "You got " + str(numpassed) + " questions right!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement