當我嘗試使用rps_game_winner
方法(見下文)CodeAcademy實驗室,它正常工作與以下輸入:Ruby的字符串對比
> rps_game_winner([ ["Dave", "P"], ["Armando", "S"] ])
valid value: p
valid value: s
=> ["Armando", "S"]
> rps_game_winner([ ["Allen", "P"], ["Richard", "P"] ])[0]
valid value: p
valid value: p
=> "Allen"
當我將其提交autograder功課,它總是失敗,並NoSuchStrategyError
。
Failure/Error: rps_game_winner([ ["Dave", "P"], ["Armando", "S"] ])[0].should eq("Armando"), "Incorrect Winner returned"
NoSuchStrategyError:
NoSuchStrategyError
有人可以幫忙嗎?謝謝。
def rps_game_winner(game)
raise WrongNumberOfPlayersError unless game.length == 2
a1=[(game[0][1]).downcase]
a2=[(game[1][1]).downcase]
a3=a1.to_s
a4=a2.to_s
valid=["r","p","s"]
if(valid.include?(a3))
puts "valid value: "+a3
else
raise NoSuchStrategyError
end
if(valid.include?(a4))
puts "valid value: "+a4
else
raise NoSuchStrategyError
end
if(win(a1, a2))
return game[0]
else
if a1.eql?(a2)
return game[0]
else
return game[1]
end
end
return game[0] if a1.eql?(a2)
end
請縮進我們的代碼。提供從你的代碼中調用的所有方法。 –