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?"
Run Code Online (Sandbox Code Playgroud)
在Ruby中,变量名不能以数字开头,但你做到了,2x = (x.to_i**2).把它写成x2 = (x.to_i**2).然后更换所有2x与x2你的代码.
另一个错误是x=x,这也是无效的.希望你输错.纠正它也.
阅读本地变量名称
局部变量名必须以小写的US-ASCII字母或具有8位的字符开头.通常,局部变量是US-ASCII兼容的,因为键入它们的键存在于所有键盘上.
(Ruby程序必须用与US-ASCII兼容的字符集编写.在这样的字符集中,如果设置了8位,则表示扩展字符.Ruby允许局部变量包含这些字符.)
局部变量名可以包含字母,数字,_(下划线或低行)或第8位的字符.