Advertisement
teslariu

extras

Feb 16th, 2022
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5.  
  6.  
  7. # lambda: funciones anónimas u inline
  8.  
  9. def suma(a,b):
  10.     return a+b
  11.    
  12. total = lambda a,b : a+b
  13.  
  14. print(suma(2,3))
  15. print(total(2,3))
  16.  
  17. # impresión de caracteres UNICODE
  18. # el símbolo de raiz
  19. print("\u221A")
  20. # el simbolo de pi
  21. print("\u03C0")
  22.  
  23. #### funciones internas o builtins
  24. # Sumar todos los elementos de una lista
  25. lista = [1,2,3,4,5,6]
  26. print(sum(lista))
  27.  
  28. # eval: resuelve cualquier operacion matemática expresada como string
  29. print(eval("232.45 + 58.25 - 78.2"))
  30.  
  31. """
  32.  
  33.  
  34. ##### Manejo de errores
  35. # En Python, los errores se manjan con algo denominado excepción. Cada
  36. # vez que una instrucciòn pueda dar error, debo ejecutarla en un bloque
  37. # try/except
  38.  
  39. while True:
  40.     a = input("Ingrese un nro entero: ")
  41.     try:
  42.         a = int(a)
  43.         break
  44.     except:
  45.         print("No has ingresado un número entero...")
  46.    
  47.    
  48.  
  49. try:
  50.     print(23/a)
  51. except:
  52.     print("No se puede dividir por cero")
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement