Created
March 3, 2013 12:31
-
-
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.
This file contains hidden or 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
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