Created
March 29, 2019 11:26
-
-
Save jimworm/541842c46f29902fe5cba8306950ff34 to your computer and use it in GitHub Desktop.
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
system('clear') | |
begin | |
runs, score = 0, 0 | |
3.times do | |
add, (i1, i2) = rand(2).zero?, [rand(750), rand(250)].sort | |
sym, answer = if add | |
['+', (i1 + i2)] | |
else | |
['-', (i2 - i1)] | |
end | |
print "Question: #{i2} #{sym} #{i1} = ?\n" | |
print 'Enter your answer: ' | |
candidate = gets | |
runs += 1 | |
if candidate.strip.to_i == answer | |
score += 1 | |
print "Correct!" | |
else | |
print "Incorrect. The correct answer was #{answer}." | |
end | |
print "\nScore is now #{score}/#{runs}" | |
print "\n\n\n" | |
end | |
rescue Interrupt => e | |
print "\nTest stopped at score #{score}/#{runs}" | |
exit | |
end | |
print "\nTest complete! Score #{score}/#{runs}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment