Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- ######### Ejemplos con módulo time
- import time
- # hora actual
- print(time.asctime())
- # impresión de fecha dd/mm/yyyy
- print(time.strftime("%d/%m/%Y", time.localtime()))
- # suspende la ejecucuión del script 10 segundos
- time.sleep(10)
- print("Chauuuuuu")
- ######### Ejemplos con módulo random
- import random
- # elegir 8 nros al azar entre 1 y 10
- for _ in range(8): # no me interesa iterar
- print(random.randint(1,10))
- # elegir un elemento al azar de una colección
- print(random.choice("Hola"))
- print(random.choice(["piedra", "papel", "tijera"]))
- # elegir un numero par al azar entre 0 y 100
- print(random.randrange(0,100,2))
- # elegir 3 nombres cualesquiera de una lista
- nombres = random.sample(["Juan","Pepe","Ana","Tito","Luisa","Kate"],3)
- print(nombres)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement