Advertisement
teslariu

adicional

Apr 13th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Escribir un programa que le pida al usuario que ingrese numeros naturales
  6. hasta que el usuario ingrese -1. Al final, el programa debe imprimir la
  7. cantidad de nros, la suma total, el mayor y el promedio.
  8. NOTA: use lo que crea necesario
  9. """
  10. numeros = []
  11. suma = 0
  12. mayor = 0
  13.  
  14. while True:
  15.     numero = int(input("Ingrese un nro natural (-1 para salir): "))
  16.     if numero == -1:
  17.         break
  18.     elif numero <= 0:
  19.         print("Debe ingresar un nro natural")
  20.     else:
  21.         numeros.append(numero)
  22.         suma = suma + numero
  23.         if numero > mayor:
  24.             mayor = numero
  25.  
  26. print(f"Promedio: {suma / len(numeros)}, suma: {suma}, mayor: {mayor}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement