我刚开始学习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