In Ruby variable names can't start with a number, but you did it, 2x = (x.to_i**2)
. Write it as x2 = (x.to_i**2)
. Then replace all 2x
with x2
in your code.
Another error will be x=x
, this is also invalid. Hope you mistyped. Correct it also.
Read this 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.