Skip to main content

Section 1.12 Evaluate Expressions-WE4-P2

Subgoals for evaluating an assignment statement.

  1. Decide order of operations
    1. Decompose as necessary
  2. Determine operator behavior based on operands
    1. Operator and operands must be compatible
  3. Solve arithmetic, expression, or operation
    1. Decompose as necessary

Subsection 1.12.1

For the assignment statements below, either give the new value of the assigned variable, or enter “invalid” if the statement would result in an error. Each problem is independent of the others (e.g. Question 2 does not depend on Question 1, only the “Given” code). If you must round a numeric answer, use 4 decimal places of precision.

Subsection 1.12.2 Expressions-WE4-P2

Given
alpha = 2
beta = 1
delta = 3 
omega = 2.5
theta = -1.3
kappa = 3.0
gamma = '4'
zeta = '2.5'

Exercises Exercises

1.
Q32: What is the value of lambda?
lambda = beta / alpha + delta
2.
Q33: What is the value of lambda?
lambda = (gamma + zeta) * delta
3.
Q34: What is the value of lambda?
lambda = (delta * omega) + gamma
4.
    Q35:
    eta = alpha * beta + (omega - theta) * gamma
    
    Why is this statement invalid?
  • Cannot perform math operations on a string
  • eta does not have a value
  • eta is a constant
  • cannot perform string operations on a number
5.
    Q36: Given
    r = 8
    
    Which statement will calculate the volume of a sphere most accurately?
  • volume = 4 // 3 * 3.14 * r * r * r
  • volume = 4 // 3 * 3.14159 * r * r * r
  • volume = 4 / 3 * 3.14 * r * r * r
  • An accurate result is not possible with these data types
You have attempted of activities on this page.