Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Escribir un programa que le pida a un usuario que ingrese una sucesión
- de nros naturales. La carga debe terminar cuando se ingrese -1, y se
- debe mostrar la cantidad de nros ingresados, la suma total de los valores y su promedio
- """
- # Estrategias de resolución
- # 1) Determinar que lógica usar (condicional, bucle)
- # 2) Determinar como vamos a guardar los valores (variables)
- numeros = []
- while True:
- numero = int(input("Ingrese un nro entero no negativo (-1 para salir): "))
- if numero >= 0:
- numeros.append(numero)
- elif numero == -1:
- break
- else:
- print("Error: número negativo")
- print(f"Cantidad de nros ingresados: {len(numeros)}")
- print(f"Suma de nros ingresados: {sum(numeros)}")
- print(f"Promedio de nros ingresados: {sum(numeros)/len(numeros):.2f}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement