Advertisement
teslariu

f

Jun 16th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Escriba un programa que permita crear una lista de
  6. nombres. Para ello, el programa tiene que pedir un número
  7. y luego solicitar esa cantidad de nombres para crear la lista.
  8. Por último, el programa tiene que mostrar la lista creada
  9. recorriendo la lista con un for.
  10. """
  11.  
  12. def ingresar_numero():
  13.     while True:
  14.         numero = input("Ingrese la cantidad de nombres: ")
  15.         if numero.isdecimal() is True:
  16.             return int(numero)
  17.         else:
  18.             print("Debes ingresar un número entero")
  19.    
  20. def cargar_nombres(total):
  21.     lista = []
  22.     for i in range(total):
  23.         nombre = input(f"Ingrese el {i+1}º nombre: ")
  24.         lista.append(nombre)
  25.     return lista
  26.    
  27. def imprimir(l):
  28.     print("\nLista:")
  29.     for e in l:
  30.         print(e)
  31.    
  32.    
  33.  
  34. ###########################################
  35.  
  36. cantidad = ingresar_numero()
  37. nombres = cargar_nombres(cantidad)
  38. imprimir(nombres)
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement