Skip to content

Instantly share code, notes, and snippets.

@EugeneAshizawa
Created July 4, 2012 02:37
Show Gist options
  • Save EugeneAshizawa/3044891 to your computer and use it in GitHub Desktop.
Save EugeneAshizawa/3044891 to your computer and use it in GitHub Desktop.
English Numbers Listening Practice
#!/usr/bin/env ruby
puts "============================================="
puts "English Numbers Listening Practice by Eugene!"
puts "============================================="
sleep 1
$practice = 10
$total_times = 0
$total_wrong = 0
$practice.times do
$voice = ["Agnes","Alex","Bruce","Fred","Junior","Kathy","Princess","Ralph","Vicki","Victoria"].sample
$number = [rand(10..99),rand(100..999),rand(1000..9999)].sample
$wrong = 0
def listen_and_answer
$total_times += 1
sleep 1
`say -v #{$voice} #{$number}`
print "Enter what you heard: "
answer = gets.chomp
if answer.to_i == $number
puts "Correct!"
else
$wrong += 1
$total_wrong += 1
if $wrong > 2
puts "The answer is #{$number}"
sleep 1
else
puts "Try it again"
listen_and_answer
end
end
end
listen_and_answer
end
puts "Score: #{ (($total_times - $total_wrong).to_f / $total_times * 100).to_i }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment