puts "Let's get started calculating your parabola. What is your A value?"
a = gets.chomp
puts "What is your B value?"
b = gets.chomp
puts "What is your C value?"
c = gets.chomp
x = x
2x = (x.to_i**2)
puts "Your parabola equation is 'y = " + a.to_s + 2x.to_s + " + " + b.to_s + x + " + " + c.to_s + "'. Would you like to go back to the beginning?"发布于 2014-02-05 21:43:28
在Ruby中,名称不能以数字开头,但是您做到了,2x = (x.to_i**2)。把它写成x2 = (x.to_i**2)。然后将代码中的所有2x替换为x2。
另一个错误是x=x,这也是无效的。希望你打错了。也更正一下。
读这个Local Variable Names
局部变量名必须以小写的US字母或设置为8位的字符开头。通常,局部变量与US兼容,因为键入它们的键存在于所有键盘上。 (Ruby程序必须用与US兼容的字符集编写.在这样的字符集中,如果设置了八位,则表示扩展字符。Ruby允许局部变量包含这些字符。) 局部变量名可能包含字母、数字、a_(下划线或低行)或设置了第八位的字符。
https://stackoverflow.com/questions/21589137
复制相似问题