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?"
最佳答案
在 Ruby 中,变量名不能以数字开头,但你做到了,2x = (x.to_i**2)
。将其写为x2 = (x.to_i**2)
。然后将代码中的所有 2x
替换为 x2
。
另一个错误是x=x
,这也是无效的。希望你打错字了。也改正一下。
阅读此内容 Local Variable Names
A local variable name must start with a lowercase US-ASCII letter or a character with the eight bit set. Typically local variables are US-ASCII compatible since the keys to type them exist on all keyboards.
(Ruby programs must be written in a US-ASCII-compatible character set. In such character sets if the eight bit is set it indicates an extended character. Ruby allows local variables to contain such characters.)
A local variable name may contain letters, numbers, an _ (underscore or low line) or a character with the eighth bit set.
关于ruby - 我怎样才能得到我正在计算的方程来向用户显示 a 值 * x 的二次方。当我尝试对 x 求平方时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21589137/