Skip to content

Instantly share code, notes, and snippets.

@dvoryankin
Created September 4, 2016 14:35
Show Gist options
  • Save dvoryankin/fb05617cd1b09201048788ed5d5bf211 to your computer and use it in GitHub Desktop.
Save dvoryankin/fb05617cd1b09201048788ed5d5bf211 to your computer and use it in GitHub Desktop.
guess the number
def start
@num = rand (1..100)
print "Enter attempts number: "
@attempts = gets.to_i
print "Guess the number, #{@attempts} attempts, "
1.upto @attempts do |i|
print "Attempt number #{i}, remaining #{@attempts - i + 1} "
x = gets.to_i
if x == @num
puts "Gotcha!"
puts "Want to play again? (Y/N)"
again = gets.to_s.strip.upcase
if again == "Y"
start
end
elsif x < @num
puts "Higher"
elsif x > @num
puts "Lower"
end
end
end
start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment