Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Ingresar numeros por teclado y calcular el promedio de todos ellos
- >>> Ingrese un numero (o presione "X" para salir): 1
- >>> Ingrese un numero (o presione "X" para salir): 9
- >>> Ingrese un numero (o presione "X" para salir): X
- >>> El promedio es 5
- """
- promedio = 0
- suma = 0
- numeros = []
- while True:
- opcion = input("Ingrese un numero (o presione 'X' para salir): ")
- if opcion == "X":
- print(f"El promedio es {promedio}")
- break
- else:
- numeros.append(float(opcion))
- suma = suma + float(opcion)
- promedio = suma / len(numeros)
Advertisement
Add Comment
Please, Sign In to add comment