Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# OpenBootCampPython
Repository to store Python boot camp.

* Ejercicio 9.A: Crea un script que le pida al usuario una lista de países (separados por comas). Éstos se deben almacenar en una lista. No debería haber países repetidos (haz uso de set). Finalmente, muestra por consola la lista de países ordenados alfabéticamente y separados por comas.
49 changes: 49 additions & 0 deletions src/exercisenine/countries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
def noContieneNumeros(lista: list[str]) -> bool:
"""Check if a list has alphabetic characters, white space included
:param lista: list of strings
:type lista:
:return: true if all elements are alphabetic characters
:rtype: bool
"""
return all(x.replace(' ', '').isalpha() for x in lista)


def transformarLista(paises: list[str]) -> list[str]:
"""Function that sort the list of strings,
remove repeated elements and capitalize the first character of the string
:param paises: string list to be treated
:type paises: list[str]
:return: transformed string list
:rtype: list[str]
"""
paises = sorted(list(x.lower() for x in paises))
paises = list(set(paises))
paises = list(x.title() for x in paises)
return paises


def inputPaises() -> list[str]:
"""Function that take user input separated by coma and return a list of strings
:return: the user input in a list of strings
:rtype: list[str]
"""
paises = input('Escribe una lista de paises separados por coma: ').split(sep=',')
return list(x.strip() for x in paises)


def getPaises() -> tuple[int, list[str]]:
"""Function that take a list of countries from user,
check if it has alphabetic characters,
apply a data transform, then return if it has errors and the list of strings.
:return: a tuple where the first element is 0 if there is error in the process
or 1 if correct. The second element is the list of strings.
:rtype: tuple[int, list[str]]
"""
paises = list()
temp = inputPaises()
if noContieneNumeros(temp):
paises.extend(temp)
transformarLista(paises)
return 0, paises
else:
return 1, temp
27 changes: 23 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
from exercisenine.countries import getPaises


def mostrarPaises(paises: list[str]):
"""Show in terminal the list of countries separated by comma.
:param paises: lista de paises
:type paises: list[str]
"""
msg = ''
msg += paises[0]
for pais in paises[1:len(paises)]:
msg += ', '
msg += pais
print(msg)


def main():
"""Main script for pythonBootCamp project
:return: None
:rtype: NoneType
"""Main script for exercise nine A
"""
pass
error, paises = getPaises()
if error == 0:
mostrarPaises(paises)
else:
print(f'Error al introducir paises: {paises}')


# Reino Unido, Italia, España, Francia
if __name__ == '__main__':
main()