Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Script que pide nros enteros positivos. La carga de nros debe concluir
- # al ingresar un cero, y debe mostrar entonces la suma de todos los numeros
- # ingresados y su promedio
- # opcion 1 (recomendada)
- lista = []
- while True:
- numero = int(input("Ingrese un nro natural (o -1 para terminar): "))
- if numero == -1:
- break
- lista.append(numero)
- print(f"Suma: {sum(lista)}")
- print(f"Promedio: {sum(lista)/len(lista)}")
- # opcion 2
- lista = []
- suma = 0
- while True:
- numero = int(input("Ingrese un nro natural (o -1 para terminar): "))
- if numero == -1:
- break
- lista.append(numero)
- suma = suma + numero
- print(f"Suma: {suma}")
- print(f"Promedio: {suma/len(lista)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement