Skip to content

Instantly share code, notes, and snippets.

@raywu
Created March 3, 2013 12:31
Show Gist options
  • Save raywu/5075932 to your computer and use it in GitHub Desktop.
Save raywu/5075932 to your computer and use it in GitHub Desktop.
Bruce Tate's 7 Languages in 7 weeks, Ch. 2.2, Bonus Question: If you're feeling the need for a little more, write a program that picks a random number. Let a player guess the number, telling the player whether the guess is too low or too high.
def guess
x = rand(10)
puts "I have a number between 0-10 in mind? What is your best guess?"
y = gets.chomp!.to_i
if x == y
print "you got it!"
elsif x < y
print "You are about #{y-x} too high in your guess.\n"
print "Hint, x is #{x}"
else x > y
print "You are about #{x-y} too low in your guess.\n"
print "Hint, x is #{x}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment