Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- # ejemplos con bibliotecas integradas
- import random
- # script que elige un nro para al azar de un solo dígito. Para comprobar
- # el correcto funcionamiento, se corre el programa 100 veces
- import random
- for _ in range(100):
- print(random.randrange(2,10,2),end=" ")
- print("\n\n\n")
- # simulacion de 100 tiradas de dado
- for _ in range(100):
- print(random.randint(1,6),end=" ")
- # elegir 5 multiplos de 3 DIFERENTES (sin reposicion) al azar entre 0 y 100
- print("\n\n\n")
- for _ in range(10):
- print(random.sample(range(3,100,3),5))
- # script que simula el juego de piedra papel o tijera
- import random
- import time
- opciones = ["piedra", "papel", "tijera"]
- while True:
- opcion = input("Elija piedra, papel o tijera: ")
- if opcion.lower() in opciones:
- opcion_usuario = opcion
- break
- else:
- print("Error, elija dfdfdsfdsf")
- opcion_pc = random.sample(opciones,1)[0]
- print(f"La compu eligió {opcion_pc}")
- print("¿Quién habrá ganado.....?")
- time.sleep(4)
- if opcion_pc == "piedra" and opcion_usuario == "papel" or \
- opcion_pc == "papel" and opcion_usuario == "tijera" or\
- opcion_pc == "tijera" and opcion_usuario == "piedra":
- print("Gano el usuario")
- elif opcion_pc == opcion_usuario:
- print("Empate")
- else:
- print("Gano la compu")
- """
- # simular cuenta regresiva que indica la explosion de una bomba. Si el
- # usuario es malicioso e ingresa un valor incorrecto, el programa debe
- # indicar el error y pedir el dato nuevamente
- # EJ
- # >> Ingrese el tiempo de explosión: No quiero
- # >> Error, debe ingresar un nro entero positivo
- # >> Ingrese el tiempo de explosión: 0
- # >> Error, debe ingresar un nro entero positivo
- # >> Ingrese el tiempo de explosión: -1.25
- # >> Error, debe ingresar un nro entero positivo
- # >> Ingrese el tiempo de explosión: 3
- # 3
- # 2
- # 1
- # BOOM
- # ayuda : usar time.sleep()
- import time
- def ingresar():
- while True:
- tiempo = input("Ingrese el tiempo para la explosión: ")
- if tiempo.isdecimal() and tiempo != "0":
- return int(tiempo)
- print("Error: debe ingresar un entero positivo")
- tiempo = ingresar()
- for t in range(tiempo,0,-1):
- print(t)
- time.sleep(1)
- print("BOOM")
Advertisement
Add Comment
Please, Sign In to add comment