Advertisement
teslariu

bibliotecas

Feb 10th, 2022
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Una biblioteca (mal llamada librería) del ingles LIBRARY es una
  5. # carpeta de módulos de Python con funciones en cada uno de ellos
  6.  
  7. # un módulo de Python es cualquier arhivo .py
  8. #
  9. """
  10.  
  11.  
  12. ej: geometria  --> cuadrado.py
  13.               --> circulo.py
  14.               --> rombo.py
  15.              
  16.  
  17. cuadrado.py:
  18. def area(lado):
  19.     pass
  20.    
  21. def perimetro(lado):
  22.     pass
  23.  
  24. Como usar la función area del cuadrado
  25.  
  26. import geometria
  27.  
  28. # llamo a la funcion area del cuadrado
  29. geometria.cuadrado.area(10)
  30.  
  31. """
  32.  
  33. # existen las bibliotecas std y las bibliotecas de terceros
  34.  
  35. # por ahora vamos a ver bibliotecas std
  36. # vamos a ver módulos de la bilioteca std
  37.  
  38. import math
  39.  
  40. # seno de 10 radianes
  41. print(math.sin(10))
  42.  
  43. # raiz cuadrada de 2
  44. print(math.sqrt(2))
  45.  
  46.  
  47. import time
  48. # fecha y hora actual
  49. print(time.asctime())
  50.  
  51. # pausar el script 10 segundos
  52. #time.sleep(10)
  53. #print("Me desperté tras 10 segundos")
  54.  
  55. # fecha y hora actual personalizada (dd/mm/yyyy HH:MM)
  56. print(time.strftime("%d/%m/%Y %H:%M:%S"))
  57.  
  58.  
  59. import random
  60. # elegir 10 enteros al azar entre 1 y 100.000
  61. for _ in range(10):
  62.     print(random.randint(1,100_000))
  63.    
  64. # elegir un numero par entre 0 y 100
  65. print(random.randrange(0,100,2))
  66.  
  67. # elegir 2 nombres de una lista
  68. paises = ["Peru", "Gabon", "Mexico", "Iran", "EEUU"]
  69. print(random.sample(paises,2))
  70.  
  71. # elegir un float al azar entre 0 y 1
  72. print(random.uniform(0,1))
  73.  
  74.  
  75.  
  76.                
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement