刚开始在7周内阅读7种语言;第一天的问题在红宝石中制作一个简单的更高或更低的游戏。当我执行我的脚本时,我收到以下错误,但我不知道原因。
编辑:我猜错了一次。
NameError:未定义的局部变量或方法
actual' for main:Object from guess_game.rb:2:in
猜测' 来自guess_game.rb:22
def guess(guess, acutal)
unless guess == actual
if guess > actual
puts 'Lower'
else
puts 'Higher'
return false
end
end
puts 'Correct'
return true
end
answer = rand(10)
game_won = false
puts 'I am thinking of a number, what is it?'
until game_won
num = gets.to_i
# Static Debug Line
puts "Guess #{num} : Answer #{answer}"
game_won = guess(num, answer)
end
答案 0 :(得分:1)
def guess(guess, actual)
unless guess == actual
if guess > actual
puts 'Lower'
else
puts 'Higher'
return false
end
end
puts 'Correct'
return true
end
问题:拼写错误,已更正