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
8cb61b17
Commit
8cb61b17
authored
Sep 28, 2015
by
muris2016
Browse files
Primera version
parent
cda66ec9
Changes
1
Hide whitespace changes
Inline
Side-by-side
calcoo.py
0 → 100644
View file @
8cb61b17
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import
sys
class
Calculadora
():
def
sum
(
self
,
a
,
b
):
return
a
+
b
def
substraction
(
self
,
a
,
b
):
return
a
-
b
def
to_number
(
num
):
try
:
if
'.'
in
num
:
return
float
(
num
)
else
:
return
int
(
num
)
except
:
sys
.
exit
(
"Error"
)
def
do_operation
(
operation
,
op1
,
op2
):
calculator
=
Calculadora
()
if
operation
==
"suma"
:
result
=
calculator
.
sum
(
op1
,
op2
)
print
(
result
)
elif
operation
==
"resta"
:
result
=
calculator
.
substraction
(
op1
,
op2
)
print
(
result
)
else
:
print
(
"Not allowed operation"
,
operation
)
if
__name__
==
"__main__"
:
op1
=
to_number
(
sys
.
argv
[
1
])
operation
=
sys
.
argv
[
2
]
op2
=
to_number
(
sys
.
argv
[
3
])
do_operation
(
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