Created
July 26, 2021 00:17
-
-
Save a2ndrade/118ccbe73679d935dd8dedd8deebb648 to your computer and use it in GitHub Desktop.
e3.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
# este es la lista vacia | |
temperaturas = [] | |
# el usuario ingresa la cantidad de dias | |
num_dias = int(input(f"¿Cuantos días se van a promediar?: ")) | |
# el ciclo del array | |
for i in range(0, num_dias): | |
temperatura = float(input(f"Ingrese la temperatura del dia {i + 1}: ")) | |
temperaturas.append(temperatura) | |
print(f"\nLas temperaturas son: {temperaturas}") | |
# inciso 6.-calcular el promedio de todas las temperaturas que guarda el arreglo | |
negativas = obtener_temperaturas_negativas(temperaturas) | |
if len(negativas) > 0: | |
print(f"\nLa temperatura promedio de temperaturas negativas es {promedio(negativas)}°") | |
else: | |
print(f"\nNo hay temperaturas negativas") | |
positivas = obtener_temperaturas_positivas(temperaturas) | |
if len(positivas) > 0: | |
print(f"\nLa temperatura promedio de temperaturas positivas es {promedio(positivas)}°") | |
else: | |
print(f"\nNo hay temperaturas positivas") | |
print(f"\nLa temperatura promedio es {promedio(temperaturas)}°") | |
def obtener_temperaturas_negativas(temperaturas): | |
temperaturas_negativas = [] | |
for temperatura in temperaturas: | |
if temperatura < 0: | |
temperaturas_negativas.append(temperatura) | |
return temperaturas_negativas | |
def obtener_temperaturas_positivas(temperaturas): | |
temperaturas_positivas = [] | |
for temperatura in temperaturas: | |
if temperatura >= 0: | |
temperaturas_positivas.append(temperatura) | |
return temperaturas_positivas | |
# estoy haciendo esta funcion para el 6.-calcular el promedio de todas las temperaturas que guarda el arreglo | |
def promedio(a): | |
# sumaT=suma total del arreglo | |
sumaT = sum(a) | |
# diasT=cantidad de dias que el usuario haya ingresado | |
diasT = len(a) | |
# formula para calcular el promedio | |
promedioT = sumaT / diasT | |
return promedioT | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment