我剛開始學習Ruby。我正在創建一個簡單的程序,但我仍然不確定如何使用它。這是我的代碼:
=begin
Filename: GameCompanyPoem.rb
Program Name: Poem Generator
Version 1.0
Created: March 7th, 2013
Purpose: To generate a poem based on key words given by the user
=end
print 'The following program will ask you to input words. Based on the words you input it will generate a poem. Now, please enter a name. '
name = gets.chomp
print 'Please enter a mammal. '
mammal = gets.chomp
print 'Now please enter a colour. '
colour1 = gets.chomp
print 'We are almost done! Please enter a place or location now. '
place = gets.chomp
print 'Now enter a verb. '
verb1 = gets.chomp
print 'And another verb. '
verb2 = gets.chomp
print 'Your poem will now be generated. Press enter to continue.
space = gets.chomp
print 'Someone by the name of ' + name + 'had a little' + mammal + ', little ' + mammal + ', little ' + mammal + ',' + name + 'had a little ' + mammal + 'its fleece was' + colour + 'as snow. It followed her to ' + place + 'one day, ' + place + 'one day, ' + place + 'one day, it made the children ' + verb1 + 'and ' + verb2 + 'to see a ' + mammal + 'at' + place + '."'
當我運行它,在最後的方法(打印),每一個空間都有這樣的錯誤:
意外tIDENtifier,期待$結束
在每一個空間,如果我填補它,然後就不見了,但它進入到下一格
閉引號上缺少''你的詩現在將產生。按enter鍵繼續。「語法突出顯示器使其更加明顯。 – 2013-03-07 18:20:17
並且在最後一個字符串末尾有一個額外的'''(雙引號)。請參閱我的回答以獲得完整修復 – BlackHatSamurai 2013-03-07 18:21:51
,它應該是coulor1,而不是顏色,就像@limelights提到的。 – BlackHatSamurai 2013-03-07 18:24:05