1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- def Grundrechenarten(c,a,d):
- if a == '+':
- result = float(c)+float(d)
- elif a == '-':
- result = float(c)-float(d)
- elif a == '*':
- result = float(c)*float(d)
- elif a == '/':
- result = float(c)/float(d)
- if result == int(result):
- result = int(result)
- return result
- def toList(s):
- L = []
- for i in s:
- if i != '\n':
- L.append(i)
- return L
- def f(i,s,S = None):
- if not S:
- S = []
-
- if i == len(s):
- return S[0]
- a = s[i]
- if a.isdigit():
- S.append(a)
- return f(i+1,s,S)
- else:
- c = S.pop()
- d = S.pop()
-
- S.append(Grundrechenarten(c,a,d))
- return f(i+1,s,S)
- x = raw_input()
- s = ""
- while x != '=\n':
- s += x
- x = raw_input() + '\n'
- print f(0,toList(s))
|