Variables and Assignment Statements
20. Spaces Don't Much Matter
Answer:
Multiplication must be shown with a *
operator. (Another answer is that 3.14y
is not a correct variable name.)
Spaces Don't Much Matter
An expression can be written without using any spaces. Operators and parentheses are enough to separate the parts of an expression. You can use one or more spaces in an expression to visually separate the parts without changing the meaning. For example, the following is a correct expression:
(hoursWorked*payRate)-deduction
The following means exactly the same:
(hoursWorked * payRate) - deduction
Use spaces wisely to make it clear what the expression means. By making things clear, you might save yourself hours of debugging. Spaces can't be placed in the middle of identifiers.
The following is NOT correct:
( hours Worked * pay Rate) -deduction
It is possible (but unwise) to be deceptive with spaces. For example, in the following:
12-4 / 2+2
it looks as if 4 is subtracted from 12, and then that the result, 8, is divided by 4. However, the spaces don't count, and the expression is the same as:
12 - 4/2 + 2
This improved arrangement of spaces makes it clear what the expression means.
Question 21:
Based on what you know about algebra, what is the value of this expression:
12 - 4/2 + 2