Skip to content

Commit 37628ce

Browse files
committed
pro3 solved
1 parent 848808d commit 37628ce

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

unit3/.pro3.py.swp

12 KB
Binary file not shown.

unit3/output.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
58.0
2-
0.142857142857
1+
(((5.5 + 9) * 2) + (6 * 1.5)) =
2+
(5.5 + 5) =
3+
(((5.5 / 2) + 4) * 5) =
4+
(5 ^ 2) =
5+
(-5 + 5) =

unit3/pro3.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from opus7.stackAsLinkedList import StackAsLinkedList
2+
3+
class Algorithms(object):
4+
5+
def __init__(self):
6+
self.stack = StackAsLinkedList()
7+
8+
def calculator(self, input, output):
9+
operators = ["+", "-", "*", "/", "^"]
10+
for line in input.readlines():
11+
for word in line.split():
12+
if word in operators:
13+
print "it is operator ", word
14+
arg2 = self.stack.pop()
15+
arg1 = self.stack.pop()
16+
self.stack.push("(%s %s %s)" % (arg1, word, arg2))
17+
elif word == "=":
18+
print "it is ="
19+
arg = self.stack.pop()
20+
output.write(arg + " = " + "\n")
21+
print "ans is ", arg
22+
else:
23+
print "it is number, push it"
24+
# make it double
25+
self.stack.push(word)
26+
27+
28+
a = Algorithms()
29+
a.calculator(open("input.txt", 'r'), open("output.txt", 'w+'))
30+

0 commit comments

Comments
 (0)