我正在學習如何使用Codecademy網站的Ruby編碼。我無法讓我的代碼執行。我一直在研究案例陳述的「更新」分支。Codecademy Ruby編程電影之夜
movies = {
oceansEleven: 4.5
}
puts "Would you like to Add, Update, Display or Delete?"
choice = gets.chomp
case choice
when "add"
print "What movie would you like to add"
title = gets.chomp
if movies[title.to_sym].nil?
print "How would you rate this movie? (1-5)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a #{rating} rating."
else
puts "That movie already exists! It's rating is #{rating}"
end
when "update"
print "What movie would you like to update?
title = gets.chomp
if movies[title].nil?
puts "Movie not found!"
else
puts "What is your new rating for the movie? (1-5)"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been updated with a #{rating} rating."
end
when "display"
puts "Movies"
when "delete"
puts "Deleted!"
else
puts "Error!"
end
下面是我收到的錯誤信息:以上
(ruby):23: syntax error, unexpected tCONSTANT, expecting keyword_end
puts "Movie not found!"
^
(ruby):25: syntax error, unexpected tCONSTANT, expecting $end
puts "What is your new rating for the movie? (1-5)"
我建議您使用語法着色編輯 - 我可以在這裏對堆棧溢出看到了問題,由於它的顏色:'打印「你想更新哪部電影?'缺少結束語。 –