Advertisement
teslariu

ej funciones

May 15th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Crear una función que
  6.  
  7. 1) tome como argumento una matriz, de cualquier
  8. dimensión, e imprima cada uno de sus números en una línea diferente.
  9. Por ejemplo, el siguiente código:
  10.  
  11. m1 = [[3.3, 6.1, 4.0], [4.9, 5.7, 6.4]]
  12. imprimir_matriz(m1)
  13.  
  14. debe imprimir:
  15.  
  16. 3.3
  17. 6.1
  18. 4.0
  19. 4.9
  20. 5.7
  21. 6.4
  22.  
  23. 2) Tome como argumento un diccionario e imprima los pares de claves y
  24. valores
  25. """
  26.  
  27. def imprimir_matriz(matriz):
  28.     for fila in matriz:
  29.         for numero in fila:
  30.             print(numero)
  31.            
  32. def imprimir_diccionario(dicc):
  33.     print("\nclave  valor")
  34.     print("------------")
  35.     for k,v in dicc.items():
  36.         print(k,v)
  37.        
  38. m1 = [[3.3, 6.1, 4.0], [4.9, 5.7, 6.4]]
  39.  
  40. agenda = {11233: 'ale', 454556: 'ale', 21344: 'pepe', 45646: 'ale'}
  41.  
  42. imprimir_matriz(m1)
  43. imprimir_diccionario(agenda)
  44.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement