Advertisement
teslariu

bibliotecas

Feb 9th, 2022
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. ######### Ejemplos con módulo time
  6. import time
  7.  
  8. # hora actual
  9. print(time.asctime())
  10.  
  11. # impresión de fecha dd/mm/yyyy
  12. print(time.strftime("%d/%m/%Y", time.localtime()))
  13.  
  14. # suspende la ejecucuión del script 10 segundos
  15. time.sleep(10)
  16.  
  17. print("Chauuuuuu")
  18.  
  19.  
  20. ######### Ejemplos con módulo random
  21. import random
  22.  
  23. # elegir 8 nros al azar entre 1 y 10
  24. for _ in range(8):                # no me interesa iterar
  25.     print(random.randint(1,10))
  26.    
  27. # elegir un elemento al azar de una colección
  28. print(random.choice("Hola"))
  29. print(random.choice(["piedra", "papel", "tijera"]))
  30.  
  31. # elegir un numero par al azar entre 0 y 100
  32. print(random.randrange(0,100,2))
  33.  
  34. # elegir 3 nombres cualesquiera de una lista
  35. nombres = random.sample(["Juan","Pepe","Ana","Tito","Luisa","Kate"],3)
  36. print(nombres)
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement