Advertisement
teslariu

repaso

Mar 21st, 2022
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Script que ingresa numeros naturales y deja de cargar datos cuando se
  5. # escribe un -1. Luego, calcula el promedio de dichos números, y muestra
  6. # el máximo y el mínimo. Luego, los imprime en forma ordenada.
  7.  
  8. numeros = []
  9. numero = int(input("Ingrese un nro natural (o '-1' para terminar): "))
  10.  
  11. while numero != -1:
  12.     numeros.append(numero)
  13.     numero = int(input("Ingrese un nro natural (o '-1' para terminar): "))
  14.    
  15. print(f"El promedio de los números es {sum(numeros)/len(numeros):.2f}")
  16. print(f"El máximo valor es {max(numeros)}")
  17. print(f"El menor valor es {min(numeros)}")
  18. numeros.sort()  # ordeno la lista
  19.  
  20. # orden descendente: numeros.sort(reverse=True)
  21.  
  22. print(f"Lista de nros ordenada: {numeros}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement