Determine operators, function calls, or method calls that will produce the value of variable
Decide order of operands and operators
Operators and operands must be compatible
Decompose as necessary
Subsection2.2.1WriteExpression-WE1-P1
ExercisesExercises
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).
sum = 0
---
sum += 1
---
sum += 2
---
sum += 3
---
sum += 4
---
sum += 5
---
print(sum)