错误:
语法错误,意外的tIDENTIFIER,期待输入结束的结束 继续==" N"
我检查了所有代码,但我仍然没有得到它。
我应该在while continue == "N"
之后添加结束代码吗?
begin
puts "|===============================================|"
puts "|Welcome to Rock Paper Scissors!!! |"
puts "|===============================================|"
begin
puts "please choose one of the following: R / P / S"
user_input = gets.chomp.upcase
end while !["R", "P", "S"].include?(user_input)
com_input = ["R", "P", "S"].sample
puts "You:#{user_input} Com:#{com_input}"
if user_input = "R" && com_input = "S" || user_input = "S" && com_input = "P" || user_input = "P" && com_input = "R"
puts "Result:You win"
elsif com_input = "R" && user_input = "S" || com_input = "S" && user_input = "P" || com_input = "P" && user_input = "R"
puts "Result:You lose"
else
puts "Result:Draw"
end
begin
puts "Play Again?: Y / N"
continue = gets.chomp.upcase
end while !["Y", "N"].include?(continue)
end whlie continue == "N"
puts "Good Bye! Thanks for playing!"
答案 0 :(得分:0)
更改whlie
的{{1}}。
此外while
正在检查while
是否继续,我认为必须N
。
Y
如果您需要,可以减少begin
...
end while continue == 'Y'
puts "Good Bye! Thanks for playing!"
和user
输入验证,并应用一些DRY:
com