Skip to main content

Section 2.2 WriteExpression-WE1-P1

Subgoals for writing expressions:.

  1. Craft name of variable
  2. Determine operators, function calls, or method calls that will produce the value of variable
  3. Decide order of operands and operators
    1. Operators and operands must be compatible
    2. Decompose as necessary

Subsection 2.2.1 WriteExpression-WE1-P1

Exercises Exercises

1.
Q1: Write an expression that will calculate a 6% tax on the number variable subtotal
2.
Q2: Write an expression that will calculate the distance travelled in miles given the variables speed (in miles per hour) and time (in hours).
3.
Q3: Write an expression that will calculate the number of pennies equivalent to a given an amount of money represented by the number variable money.
Hint.
$1.25 is equivalent to 125 pennies.
4.
Q4: Write an expression that will calculate the simple interest given the initial principal variable P, the interest rate variable R, and the time variable t. The equation for simple interest is
\begin{equation*} A = P(1 + \frac{R}{100}T) \end{equation*}
5.
Q5: Put the code in the right order to create a program that will calculate and print the sum of the first 5 natural numbers (you must sum the numbers in order).
You have attempted of activities on this page.