WGU D278 OA Exam | Scripting and
Programming Foundations | Study
Questions and Answers Rated A+ |
2025/2026 Guide
Type Conversions - Correct Answer - Converts one data type to another
(e.g., integer → float).
Implicit Conversions (Automatic) - Correct Answer - Arithmetic Operators
(+, *, etc.): If either operand is a float, the other is converted to float, and
a floating-point operation is performed.
Ex: 0.504 * numBirths (if numBirths is an integer) → numBirths is
converted to float.
Assignments (=): The right side's type is converted to match the left
side's type.
Ex: Assigning a float to an integer variable will drop the fraction.
Conversions - Correct Answer - Integer → Float: Adds a .0.
Ex: 25 → 25.0.
Float → Integer: Drops the fractional part.
Ex: 4.9 → 4.
,Type Casting - Correct Answer - Explicitly convert a value from one data
type to another.
Why Use It? : To control the type of operation or result.
Ex: Ensure floating-point division instead of integer division.
How to Type Cast: Convert
Integer to Float:Multiply the integer by 1.0.
Ex: myIntVar * 1.0 → Converts 7 (integer) to 7.0 (float).
Ex. Use Case:
Without Casting: → Integer division → Result: 3
With Casting: (7 * 1.0) / 2 → Floating-point division → Result: 3.5
Modulo Operator (%) - Correct Answer - Calculates the remainder of
dividing two integers.
Ex:
9 % 5 → Result: 4Reason: 9 = 5 * 1 + 4 (remainder: 4).
70 % 7 → Result: 0Reason: 70 = 7 * 10 + 0 (no remainder).
1 % 2 → Result: 1Reason: 1 = 2 * 0 + 1 (remainder: 1).
Key Rule:
Only valid for integer operands.
Ex: 10 % 4.0 → Not valid (one operand is a float).
,Constants - Correct Answer - A named value that cannot change during
program execution.
Uses: Store mathematical/physical constants:
Ex: PI, SPEED_OF_LIGHT.
Replace literal numbers to improve code readability:Ex:Less clear:
newPrice = origPrice - 5.
More clear: newPrice = origPrice - PRICE_DISCOUNT.
Naming Convention: Use ALL UPPERCASE with underscores:
Example: PRICE_DISCOUNT, KG_PER_POUND.
Branches - Correct Answer - A branch is a sequence of statements that
executes only if a condition is true.
Decision: Evaluates a condition to decide which branch to execute.
Flow: If true → First branch executes. If false → Second branch
executes.
Branches rejoin after execution.
If-Else Branches - Correct Answer - Executes one branch if a condition is
true, and another branch if false.
If branch: Executes when the condition is true.
, Else branch: Executes when the condition is false.
If-ElseIf Branches - Correct Answer - A branch can contain additional
decisions and branches.
A series of decisions in the false branch forms
if-elseif branches.
Usage: Detects specific values of a variable.
Ex: Check if numYears equals 1, 25, or 50.
Equality Operator (==): - Correct Answer - Evaluates true if both sides
are equal.
Ex: numYears == 10 → True if numYears is 10.
Important: Use == for equality, not =.
Nested If-Else Branches - Correct Answer - Nested branches: An if-else
branch can contain another if-else branch within it.
Key Points: A branch's statements can include any valid statements,
including another if-else branch.
Nested branches can be structured in various ways and may use
different variables
Multiple If Branches - Correct Answer - A series of independent if
decisions in sequence.
Key Difference:
Programming Foundations | Study
Questions and Answers Rated A+ |
2025/2026 Guide
Type Conversions - Correct Answer - Converts one data type to another
(e.g., integer → float).
Implicit Conversions (Automatic) - Correct Answer - Arithmetic Operators
(+, *, etc.): If either operand is a float, the other is converted to float, and
a floating-point operation is performed.
Ex: 0.504 * numBirths (if numBirths is an integer) → numBirths is
converted to float.
Assignments (=): The right side's type is converted to match the left
side's type.
Ex: Assigning a float to an integer variable will drop the fraction.
Conversions - Correct Answer - Integer → Float: Adds a .0.
Ex: 25 → 25.0.
Float → Integer: Drops the fractional part.
Ex: 4.9 → 4.
,Type Casting - Correct Answer - Explicitly convert a value from one data
type to another.
Why Use It? : To control the type of operation or result.
Ex: Ensure floating-point division instead of integer division.
How to Type Cast: Convert
Integer to Float:Multiply the integer by 1.0.
Ex: myIntVar * 1.0 → Converts 7 (integer) to 7.0 (float).
Ex. Use Case:
Without Casting: → Integer division → Result: 3
With Casting: (7 * 1.0) / 2 → Floating-point division → Result: 3.5
Modulo Operator (%) - Correct Answer - Calculates the remainder of
dividing two integers.
Ex:
9 % 5 → Result: 4Reason: 9 = 5 * 1 + 4 (remainder: 4).
70 % 7 → Result: 0Reason: 70 = 7 * 10 + 0 (no remainder).
1 % 2 → Result: 1Reason: 1 = 2 * 0 + 1 (remainder: 1).
Key Rule:
Only valid for integer operands.
Ex: 10 % 4.0 → Not valid (one operand is a float).
,Constants - Correct Answer - A named value that cannot change during
program execution.
Uses: Store mathematical/physical constants:
Ex: PI, SPEED_OF_LIGHT.
Replace literal numbers to improve code readability:Ex:Less clear:
newPrice = origPrice - 5.
More clear: newPrice = origPrice - PRICE_DISCOUNT.
Naming Convention: Use ALL UPPERCASE with underscores:
Example: PRICE_DISCOUNT, KG_PER_POUND.
Branches - Correct Answer - A branch is a sequence of statements that
executes only if a condition is true.
Decision: Evaluates a condition to decide which branch to execute.
Flow: If true → First branch executes. If false → Second branch
executes.
Branches rejoin after execution.
If-Else Branches - Correct Answer - Executes one branch if a condition is
true, and another branch if false.
If branch: Executes when the condition is true.
, Else branch: Executes when the condition is false.
If-ElseIf Branches - Correct Answer - A branch can contain additional
decisions and branches.
A series of decisions in the false branch forms
if-elseif branches.
Usage: Detects specific values of a variable.
Ex: Check if numYears equals 1, 25, or 50.
Equality Operator (==): - Correct Answer - Evaluates true if both sides
are equal.
Ex: numYears == 10 → True if numYears is 10.
Important: Use == for equality, not =.
Nested If-Else Branches - Correct Answer - Nested branches: An if-else
branch can contain another if-else branch within it.
Key Points: A branch's statements can include any valid statements,
including another if-else branch.
Nested branches can be structured in various ways and may use
different variables
Multiple If Branches - Correct Answer - A series of independent if
decisions in sequence.
Key Difference: