Adivinar numero


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. intentos = 0
  2.  
  3. puts"adivinalo"
  4.  
  5. secreto = rand(20)
  6. while (intentos < 5) do
  7. numero_jugador = Integer(gets.chomp) # teclado
  8. intentos = intentos + 1 # intentos += 1
  9.  
  10. if numero_jugador < secreto
  11. puts "tu numero es menor que el secreto"
  12. elsif numero_jugador > secreto
  13. puts "tu numero es mayor que el secreto"
  14. else numero_jugador == secreto
  15. break
  16. end
  17.  
  18. end
  19.  
  20. if numero_jugador == secreto
  21. puts "adivinaste mi numero en #{intentos} intentos"
  22. end
  23.  
  24. if numero_jugador != secreto
  25. puts "has perdido! mi numero secreto era #{secreto}"
  26. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.