Advertisement
Rafsys

Untitled

Jun 2nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from random import *
  2.  
  3. def generaNumeroAleatorio(minimo,maximo):
  4.  
  5. try:
  6. if minimo > maximo:
  7. aux = minimo
  8. minimo = maximo
  9. maximo = aux
  10.  
  11. return randint(minimo, maximo)
  12. except TypeError:
  13. print("Debes escribir numeros")
  14. return -1
  15.  
  16. numero_buscado = generaNumeroAleatorio(1,100)
  17.  
  18. encontrado = False
  19. intentos = 0
  20.  
  21. while not encontrado:
  22.  
  23. numero_usuario = int(input("Introduce el número buscado: "))
  24.  
  25. if numero_usuario > numero_buscado:
  26. print("El número que buscas es menor")
  27. intentos = intentos +1
  28. elif numero_usuario < numero_buscado:
  29. print("El numero que buscas es mayor")
  30. intentos = intentos +1
  31. else:
  32. encontrado = True
  33. print("Has acertado el número correcto es " , numero_usuario, " te ha llevado ", intentos," intentos")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement