teslariu

adivinar

Jul 19th, 2022
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Hacer una funcion que pida un nombre de usuario y le pida al mismo
  5. # que adivine un nro entero entre 0 y 100, ir contando los intentos y
  6. # tras 5 intentos fallidos indicar perdiste y mostrar el nro
  7. # oculto = random.randrange(101)
  8.  
  9. import random
  10.  
  11. def adivinar(intentos):
  12.     oculto = random.randrange(3)
  13.     for i in range(intentos):
  14.         numero = int(input("Ingrese el nro: "))
  15.         if numero == oculto:
  16.             return "Felicitaciones, has adivinado el nro oculto"
  17.         else:
  18.             print(f"No has acertado. Te restan {intentos-1-i} intentos")
  19.     return f"El nro a adivinar era {oculto}"
  20.  
  21. nombre = input("Ingrese su nombre: ")
  22. print(f"""
  23.    Hola {nombre}, bienvenido.
  24.    Tiene n intentos para adivinar un nro entero entero entre 0 y 100
  25.    """)
  26. intentos = int(input("Ingrese la cantidad de intentos: "))
  27. print(adivinar(intentos))
  28.  
Advertisement
Add Comment
Please, Sign In to add comment