teslariu

uso de bibliotecas

Jul 6th, 2023
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. # ejemplos con bibliotecas integradas
  6. import random
  7.  
  8. # script que elige un nro para al azar de un solo dígito. Para comprobar
  9. # el correcto funcionamiento, se corre el programa 100 veces
  10. import random
  11.  
  12. for _ in range(100):
  13.    print(random.randrange(2,10,2),end=" ")
  14.    
  15. print("\n\n\n")
  16.  
  17. # simulacion de 100 tiradas de dado
  18. for _ in range(100):
  19.    print(random.randint(1,6),end=" ")
  20.  
  21. # elegir 5 multiplos de 3 DIFERENTES (sin reposicion) al azar entre 0 y 100
  22. print("\n\n\n")
  23. for _ in range(10):
  24.    print(random.sample(range(3,100,3),5))
  25.  
  26.  
  27. # script que simula el juego de piedra papel o tijera
  28. import random
  29. import time
  30. opciones = ["piedra", "papel", "tijera"]
  31.  
  32. while True:
  33.    opcion = input("Elija piedra, papel o tijera: ")
  34.    if opcion.lower() in opciones:
  35.        opcion_usuario = opcion
  36.        break
  37.    else:
  38.        print("Error, elija dfdfdsfdsf")
  39.        
  40. opcion_pc = random.sample(opciones,1)[0]
  41. print(f"La compu eligió {opcion_pc}")
  42. print("¿Quién habrá ganado.....?")
  43. time.sleep(4)
  44.  
  45. if opcion_pc == "piedra" and opcion_usuario == "papel" or \
  46.    opcion_pc == "papel" and opcion_usuario == "tijera" or\
  47.    opcion_pc == "tijera" and opcion_usuario == "piedra":
  48.        print("Gano el usuario")
  49.        
  50. elif opcion_pc == opcion_usuario:
  51.    print("Empate")
  52.    
  53. else:
  54.    print("Gano la compu")
  55. """
  56. # simular cuenta regresiva que indica la explosion de una bomba. Si el
  57. # usuario es malicioso e ingresa un valor incorrecto, el programa debe
  58. # indicar el error y pedir el dato nuevamente
  59. # EJ
  60. # >> Ingrese el tiempo de explosión: No quiero
  61. # >> Error, debe ingresar un nro entero positivo
  62. # >> Ingrese el tiempo de explosión: 0
  63. # >> Error, debe ingresar un nro entero positivo
  64. # >> Ingrese el tiempo de explosión: -1.25
  65. # >> Error, debe ingresar un nro entero positivo
  66. # >> Ingrese el tiempo de explosión: 3
  67. # 3
  68. # 2
  69. # 1
  70. # BOOM
  71. # ayuda : usar time.sleep()
  72.  
  73. import time
  74.  
  75. def ingresar():
  76.     while True:
  77.         tiempo = input("Ingrese el tiempo para la explosión: ")
  78.         if tiempo.isdecimal() and tiempo != "0":
  79.             return int(tiempo)
  80.         print("Error: debe ingresar un entero positivo")
  81.  
  82.  
  83.  
  84.    
  85. tiempo = ingresar()
  86. for t in range(tiempo,0,-1):
  87.     print(t)
  88.     time.sleep(1)
  89.    
  90. print("BOOM")
Advertisement
Add Comment
Please, Sign In to add comment