Skip to content

Commit

Permalink
Control de input errores en listas
Browse files Browse the repository at this point in the history
  • Loading branch information
wlizama committed Nov 12, 2018
1 parent d8b8672 commit 54cc268
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

str_inputs = []

# Helpers

def lineSeparator(len):
return LINE_SEPARADOR * len
Expand Down Expand Up @@ -60,6 +61,10 @@ def getListaTiposDocs():

@printInputValues
def getInputEmpresa(str_msg):

is_error = True
empresa_seleccionada = None

print("""\
\nLISTA DE EMPRESAS\
\n{0}\
Expand All @@ -74,13 +79,28 @@ def getInputEmpresa(str_msg):
empresa.ruc,
empresa.razon_social))

indx_empresa_seleccionada = int(input(str_msg)) - 1

return empresas[indx_empresa_seleccionada]

while is_error:
is_error = True
try:
indx_empresa_seleccionada = int(input(str_msg))
if indx_empresa_seleccionada > 0:
empresa_seleccionada = empresas[indx_empresa_seleccionada - 1]
is_error = False
else:
print("‼ El valor debe ser mayor a Cero ( 0 ).")
except ValueError as verr:
print("‼ El valor ingresado no es númerico.")
except IndexError as ierr:
print("‼ Debe seleccionar una de las empresas en la lista.")

return empresa_seleccionada

@printInputValues
def getInputTipoDoc(str_msg):

is_error = True
tipo_doc_seleccionado = None

print("""\
\nLISTA TIPOS DE DOCUMENTOS\
\n{0}\
Expand All @@ -95,9 +115,21 @@ def getInputTipoDoc(str_msg):
tipo_doc.codigo,
tipo_doc.descripcion))

indx_tipos_doc_seleccionado = int(input(str_msg)) - 1

return tipos_docs[indx_tipos_doc_seleccionado]
while is_error:
is_error = True
try:
indx_tipo_doc_seleccionado = int(input(str_msg))
if indx_tipo_doc_seleccionado > 0:
tipo_doc_seleccionado = tipos_docs[indx_tipo_doc_seleccionado - 1]
is_error = False
else:
print("‼ El valor debe ser mayor a Cero ( 0 ).")
except ValueError as verr:
print("‼ El valor ingresado no es númerico.")
except IndexError as ierr:
print("‼ Debe seleccionar uno de los documentos en la lista.")

return tipo_doc_seleccionado


@printInputValues
Expand Down

0 comments on commit 54cc268

Please sign in to comment.