Advertisement
teslariu

notas

Jan 12th, 2022
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Hacer un script que, dada una lista de notas, calcule su promedio
  5. # Si se animan, indicar también la nota máxima y la mínima
  6.  
  7. notas = [4,8,7,10,9,5,6,7,8,9,3,5,8]
  8.  
  9.  
  10. # Algoritmo estandar de la mayoría de los lenguajes de programación
  11. maximo = -1
  12. minimo = 11
  13. i=0
  14. suma = 0
  15. while i < len(notas):
  16.     suma = suma + notas[i]
  17.     if notas[i] > maximo:
  18.         maximo = notas[i]
  19.     elif notas[i] < minimo:
  20.         minimo = notas[i]
  21.     i = i + 1
  22.    
  23. print(f"Promedio: {suma/len(notas)}")
  24. print(f"Máximo: {maximo}, mínimo: {minimo}")
  25.  
  26.  
  27. # Forma correcta de hacerlo en Python
  28. # Propiedad: TODA COLECCION ES ITERABLE
  29. print(f"Promedio: {sum(notas)/len(notas)} - Mínimo: {min(notas)} - Máximo: {max(notas)}")
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement