Advertisement
teslariu

for while

Jan 8th, 2022
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # condicional (indefinido) while
  5. # script que calcula el promedio de una lista de notas con while
  6. """
  7. notas = [7,8,10,9,7,8,5,6,3,10,8,9] #len(notas) --> 12
  8.  
  9. i = 0
  10. suma = 0
  11.  
  12. while i < len(notas):
  13.     suma = suma + notas[i]
  14.     i += 1
  15.    
  16. promedio = suma / len(notas)
  17.  
  18. print("El promedio es", promedio)
  19.  
  20. # script que calcula el promedio de una lista de notas con for
  21. # for <iterador> in <iterable>
  22. # TODA COLECCION ES ITERABLE
  23.  
  24. suma = 0
  25. for nota in notas:
  26.     suma = suma + nota
  27. promedio = suma / len(notas)
  28.  
  29. print("El promedio es", promedio)  
  30.  
  31.  
  32. for letra in "murcielago":
  33.     print(letra, end="_")
  34.    
  35. print("\n-----------------")
  36.    
  37.    
  38. dicc = {"brown":"marron", "red":"rojo", "blue":"azul"}
  39. for k,v in dicc.items():
  40.     print(k,v)
  41.    
  42. nombres = ["Ale","Luisa","Juana"]
  43. apellidos = ["Perez","Garcia","Fernandez"]
  44. notas = [8,9,7]
  45.  
  46. for nombre, apellido, nota in zip(nombres,apellidos,notas):
  47.     print(nombre,apellido,nota)
  48. """
  49. for i in range(100,-5,-12):
  50.     print(i, i**2)
  51.    
  52. #range(v.inicial, tope, incremento)
  53. #range(v.inicial, tope)   incremento por defecto 1
  54. #range(tope)            v.inicial x defecto 0 e incremento x defecto 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement