Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import operator
  2.  
  3. math_functions = {
  4.     '+': operator.add,
  5.     '-': operator.sub,
  6.     '*': operator.mul,
  7.     '/': operator.truediv
  8. }
  9.  
  10. #with open("output_dev_20k", "r") as f:
  11. #    output = f.read().split('\n')
  12. output = [
  13.     '-190816',
  14.     '261523620432',
  15.     '583719',
  16.     '0.9739',
  17.     '719901',
  18. ]
  19.  
  20. #with open("tst2012.from", "r") as f:
  21. #    from_data = f.read().split('\n')
  22. from_data = [
  23.     '219459 - 410275',
  24.     '265572 * 984756',
  25.     '584986 - 1267',
  26.     '879174 / 902737',
  27.     '520354 + 199547',
  28. ]
  29.  
  30.  
  31.  
  32. right = 0
  33. total = 0
  34.  
  35. for n, _ in enumerate(output):
  36.     try:
  37.  
  38.         num = from_data[n].split(' ')
  39.         real_answer = math_functions[num[1]](int(num[0]), int(num[2]))
  40.         if num[1] == '/':
  41.             real_answer = round(real_answer, 4)
  42.         predicted_answer = float(output[n])
  43.  
  44.         if predicted_answer == real_answer:
  45.             right += 1
  46.         total += 1
  47.         print(real_answer, predicted_answer)
  48.     except Exception as e:
  49.         print(str(e))
  50.  
  51. print(right / total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement