Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
DELGADO VALENCIA, JORGE
ptavi-p2
Commits
e79f72d0
Commit
e79f72d0
authored
Sep 29, 2015
by
muris2016
Browse files
Version con diccionario
parent
8cb61b17
Changes
1
Hide whitespace changes
Inline
Side-by-side
calc.py
100755 → 100644
View file @
e79f72d0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import
sys
...
...
@@ -14,7 +11,7 @@ def to_number(num):
else
:
return
int
(
num
)
except
:
sys
.
exit
(
"Error"
)
sys
.
exit
(
"Error
: Non numerical parameters
"
)
def
sum
(
op1
,
op2
):
...
...
@@ -25,16 +22,17 @@ def substraction(op1, op2):
return
op1
-
op2
def
do_operation
(
operation
,
op1
,
op2
):
if
operation
==
"suma"
:
print
(
sum
(
op1
,
op2
))
elif
operation
==
"resta"
:
print
(
substraction
(
op1
,
op2
))
else
:
print
(
"Not allowed operation "
,
operation
)
def
do_operation
(
operations
,
operation
,
op1
,
op2
):
try
:
return
operations
[
operation
](
op1
,
op2
)
except
KeyError
:
sys
.
exit
(
"Not allowed operation "
+
operation
)
if
__name__
==
"__main__"
:
operations
=
{
"suma"
:
sum
,
"resta"
:
substraction
}
op1
=
to_number
(
sys
.
argv
[
1
])
operation
=
sys
.
argv
[
2
]
op2
=
to_number
(
sys
.
argv
[
3
])
do_operation
(
operation
,
op1
,
op2
)
print
(
do_operation
(
operations
,
operation
,
op1
,
op2
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment