Advertisement
xah

Sample Problem 2: Are My Sums Right?

xah
Mar 24th, 2017 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. sample = input()
  2. legend = []
  3.  
  4. while sample:
  5.     if sample == '#':
  6.         break
  7.    
  8.     for s in range(len(sample)):
  9.         if sample[s] == '+':
  10.             a = 'a'
  11.             o = s
  12.         elif sample[s] == '-':
  13.             a = 'b'
  14.             o = s
  15.         elif sample[s] == '*':
  16.             a = 'c'
  17.             o = s
  18.         elif sample[s] == '=':
  19.             e = s
  20.  
  21.     if a == 'a':
  22.         note = int(sample[:o]) + int(sample[o+1:e]) == int(sample[e+1:])
  23.     elif a == 'b':
  24.         note = int(sample[:o]) - int(sample[o+1:e]) == int(sample[e+1:])
  25.     elif a == 'c':
  26.         note = int(sample[:o]) * int(sample[o+1:e]) == int(sample[e+1:])
  27.  
  28.     if note:
  29.         legend.append('Correct')
  30.     else:
  31.         legend.append('Wrong')
  32.  
  33.     sample = input()
  34.  
  35. for l in legend:
  36.     print(l)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement