-
-
Save eveadele/9100605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number = rand(1...1000) | |
guess = "" | |
while guess != number | |
print "Guess a number between 0 and 1000. " | |
guess = Integer(gets) rescue nil | |
if guess == nil || guess <= 0 || guess >= 1000 | |
puts "Invalid input, must enter a number between 0 and 1000." | |
break | |
elsif guess < number | |
puts "Too low, try again." | |
elsif guess > number | |
puts "Too high, try again." | |
else | |
puts "Congratulations, you guessed the number!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment