Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c4cs-f17-rpn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
hyunchun
c4cs-f17-rpn
Commits
5b315b9d
Commit
5b315b9d
authored
7 years ago
by
hyunchun
Browse files
Options
Downloads
Patches
Plain Diff
simplified rpn
parent
3b9c66de
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
__pycache__/rpn.cpython-35.pyc
+0
-0
0 additions, 0 deletions
__pycache__/rpn.cpython-35.pyc
rpn.py
+14
-10
14 additions, 10 deletions
rpn.py
with
14 additions
and
10 deletions
__pycache__/rpn.cpython-35.pyc
+
0
−
0
View file @
5b315b9d
No preview for this file type
This diff is collapsed.
Click to expand it.
rpn.py
+
14
−
10
View file @
5b315b9d
#!/usr/bin/env python3
import
operator
ops
=
{
'
+
'
:
operator
.
add
,
'
-
'
:
operator
.
sub
,
}
def
calculate
(
myarg
):
stack
=
list
()
for
token
in
myarg
.
split
():
if
token
==
'
+
'
:
arg2
=
stack
.
pop
()
arg1
=
stack
.
pop
()
result
=
arg1
+
arg2
stack
.
append
(
result
)
elif
token
==
'
-
'
:
try
:
stack
.
append
(
int
(
token
))
except
ValueError
:
arg2
=
stack
.
pop
()
arg1
=
stack
.
pop
()
result
=
arg1
-
arg2
function
=
ops
[
token
]
result
=
function
(
arg1
,
arg2
)
stack
.
append
(
result
)
else
:
stack
.
append
(
int
(
token
))
print
(
stack
)
#
print(stack)
return
stack
.
pop
()
def
main
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment