Advertisement
teslariu

while1

Dec 2nd, 2021
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Ingresar numeros por pantalla y agregarlos a una lista. Cuando se
  5. # ingrese -1, se debe terminar el ingreso de datos e imprimir la lista
  6. # de nros
  7.  
  8. #################### forma 1 (no recomendada)
  9. lista = [] 
  10. numero = int(input("Ingrese un número entero: "))
  11.  
  12. while numero != -1:
  13.     lista.append(numero)
  14.     numero = int(input("Ingrese otro número entero: "))
  15.  
  16. for numero in lista:
  17.     print(numero, end="_")
  18.  
  19. ################# forma recomendada
  20.  
  21. lista = []
  22. while True:
  23.     numero = int(input("Ingrese un número entero: "))
  24.     if numero == -1:
  25.         break
  26.     lista.append(numero)
  27.  
  28. for numero in lista:
  29.     print(numero, end="_")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement