gpt4 book ai didi

ruby - 我的Ruby编程代码有什么问题?

转载 作者:行者123 更新时间:2023-12-03 08:16:06 26 4
gpt4 key购买 nike

该代码应该起作用。但是每次我在Ruby上打开它时,Ruby几乎都会立即关闭,因为它无法读取代码中的内容。因此,显然代码中存在错误,但我检查了所有内容,但似乎找不到。我需要一些帮助来使此代码正常工作。提前谢谢你!

puts 'Enter the number of the current month using the 12 months per year scale. Ex. January would be 1, February would be 2, March would be 3, etc...'
month=gets.chomp
case month
when '1'..'3'
fee='$45'
when'4'..'5'
fee='$55'
when'7'..'8'
fee='$65'
else
fee='$0.00'
end
puts'The fee to apply for the competition is ' + fee + '.00 when you apply on the date of today, ' + Time.now.to_s +'.'
puts 'If your fee came up as $0.00, then that is because the competition has ended. But do not worry, there is always next year!'
sleep 20

最佳答案

这是Ruby告诉我的语法错误是:

temp.rb:13: syntax error, unexpected tUPLUS, expecting $end
... of today, ' + Time.now.to_s +'.'

+'.'之间添加空格可修复语法错误。

您可以通过从命令行运行Ruby自己解决这个问题。我认为您正在运行Windows。要进入命令提示符,可以按Windows键和R键打开运行对话框。在这里,您可以输入 cmd并按Enter打开命令提示符。然后,您可以使用 cd更改当前目录,并使用 ruby运行您的Ruby脚本(假设Ruby在 PATH中)。您的 session 可能如下所示:

C:\Documents and Settings\Madelyn Grewal> cd Desktop

C:\Documents and Settings\Madelyn Grewal\Desktop> ruby myscript.rb
myscript.rb:13: syntax error, unexpected tUPLUS, expecting $end
... of today, ' + Time.now.to_s +'.'

C:\Documents and Settings\Madelyn Grewal\Desktop>

关于ruby - 我的Ruby编程代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com