Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Escriba un programa que permita crear una lista de
- nombres. Para ello, el programa tiene que pedir un número
- y luego solicitar esa cantidad de nombres para crear la lista.
- Por último, el programa tiene que mostrar la lista creada
- recorriendo la lista con un for.
- """
- def ingresar_numero():
- while True:
- numero = input("Ingrese la cantidad de nombres: ")
- if numero.isdecimal() is True:
- return int(numero)
- else:
- print("Debes ingresar un número entero")
- def cargar_nombres(total):
- lista = []
- for i in range(total):
- nombre = input(f"Ingrese el {i+1}º nombre: ")
- lista.append(nombre)
- return lista
- def imprimir(l):
- print("\nLista:")
- for e in l:
- print(e)
- ###########################################
- cantidad = ingresar_numero()
- nombres = cargar_nombres(cantidad)
- imprimir(nombres)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement