Advertisement
teslariu

for

Mar 21st, 2022
1,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # for
  4. # for <iterador> in <iterable>:
  5. #       sentencias
  6. # toda colección es iterable
  7.  
  8. # si el iterable es una lista de nros conviene usar range
  9.  
  10. nombres = ["Ana", "Juan", "Oscar"]
  11.  
  12. for nombre in nombres:
  13.     print(nombre)
  14.  
  15. numeros =  [1,2,3,4,5,6,7,8,9,10]
  16. print("\nCuadrados y cubos del 1 al 10")
  17. for numero in numeros:
  18.     print(f"{numero:>3} {numero**2:>4} {numero**3:>5}")
  19.  
  20.  
  21. print("\nCuadrados y cubos de multiplos de 3 entre 1000 y 1")
  22. for numero in range(999,0,-3):
  23.     print(f"{numero:>5} {numero**2:>10} {numero**3:>15}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement