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
de658c50
Commit
de658c50
authored
Oct 05, 2015
by
muris2016
Browse files
Errores sobre argumentos capturados
parent
4f01899b
Changes
1
Hide whitespace changes
Inline
Side-by-side
calc.py
View file @
de658c50
...
...
@@ -10,10 +10,20 @@ def to_number(num):
return
float
(
num
)
else
:
return
int
(
num
)
except
:
except
ValueError
:
sys
.
exit
(
"Error: Non numerical parameters"
)
def
take_args
():
if
len
(
sys
.
argv
)
!=
4
:
sys
.
exit
(
"Error: incorrect parameters
\n
Use: script op1 operation op2"
)
else
:
op1
=
to_number
(
sys
.
argv
[
1
])
operation
=
sys
.
argv
[
2
]
op2
=
to_number
(
sys
.
argv
[
3
])
return
op1
,
operation
,
op2
def
sum
(
op1
,
op2
):
return
op1
+
op2
...
...
@@ -31,8 +41,6 @@ def do_operation(operations, operation, op1, op2):
if
__name__
==
"__main__"
:
op1
,
operation
,
op2
=
take_args
()
operations
=
{
"suma"
:
sum
,
"resta"
:
substraction
}
op1
=
to_number
(
sys
.
argv
[
1
])
operation
=
sys
.
argv
[
2
]
op2
=
to_number
(
sys
.
argv
[
3
])
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