New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Scripting and Programming Foundations Exam - Topic 2 Question 2 Discussion

Actual exam question for WGU's WGU Scripting and Programming Foundations exam
Question #: 2
Topic #: 2
[All WGU Scripting and Programming Foundations Questions]

The steps in an algorithm to calculate the positive difference in given values, x and y, are given in no particular order:

Put Diff to output.

Set Diff = x - y.

If y > x, set Diff = y - x.

Declare variable Diff.What is the first step of the algorithm?

Show Suggested Answer Hide Answer
Suggested Answer: D

Comprehensive and Detailed Explanation From Exact Extract:

The algorithm calculates the positive difference between x and y (i.e., |x - y|). According to foundational programming principles, an algorithm's steps must be executed in a logical order, and variables must be declared before they are used.

Steps Analysis:

Declare variable Diff: Creates the variable Diff to store the result. Must occur first, as other steps use Diff.

Set Diff = x - y: Computes the difference, assuming x >= y. Requires Diff to exist.

If y > x, set Diff = y - x: Adjusts Diff to ensure it's positive if y > x. Requires Diff to exist.

Put Diff to output: Outputs the final result. Must occur last, after Diff is computed.

Logical Order:

Declare Diff (create variable).

Set Diff = x - y (initial difference).

If y > x, set Diff = y - x (ensure positive).

Output Diff.

Option A: 'Put Diff to output.' Incorrect. Outputting Diff requires it to be computed, which happens after declaration and calculation.

Option B: 'Set Diff = x - y.' Incorrect. Setting Diff requires Diff to be declared first.

Option C: 'If y > x, set Diff = y - x.' Incorrect. This step uses Diff, so declaration must precede it.

Option D: 'Declare variable Diff.' Correct. Declaring Diff is the first step, as all other steps depend on Diff existing.

Certiport Scripting and Programming Foundations Study Guide (Section on Algorithms and Variables).

Python Documentation: ''Variable Declaration'' (https://docs.python.org/3/reference/simple_stmts.html#assignment-statements).

W3Schools: ''C Variables'' (https://www.w3schools.com/c/c_variables.php).


Contribute your Thoughts:

0/2000 characters
Brice
14 hours ago
Wait, are we sure it's not B?
upvoted 0 times
...
Tish
6 days ago
Totally agree, it has to be D!
upvoted 0 times
...
Emelda
11 days ago
If y > x, set Diff = y - x. Ah, the old "flip the order" trick.
upvoted 0 times
...
Keneth
16 days ago
Put Diff to output. Wait, shouldn't we calculate it first?
upvoted 0 times
...
Remedios
21 days ago
If y > x, set Diff = y - x. Hmm, I wonder if that's a special case.
upvoted 0 times
...
Alecia
26 days ago
Set Diff = x - y. Seems like the logical first step to me.
upvoted 0 times
...
Christiane
1 month ago
I feel like setting Diff to x - y could be the first step, but it might make more sense to declare it first. I'm confused!
upvoted 0 times
...
Kallie
1 month ago
I practiced a similar question where the first step was about declaring variables too, but I can't recall if that's always the case.
upvoted 0 times
...
Irma
1 month ago
I'm not entirely sure, but I remember something about initializing variables first. So maybe it's option D?
upvoted 0 times
...
Malcom
2 months ago
I think the first step should be to declare the variable Diff, right? That seems like a logical starting point.
upvoted 0 times
...
Suzan
2 months ago
I'm not totally sure about this one. The steps seem a bit mixed up. I'm leaning towards option A, putting Diff to output, since that's the final step in the algorithm. But I'll double-check my reasoning before answering.
upvoted 0 times
...
Mona
2 months ago
Easy peasy! The first step is clearly setting Diff = x - y. That's the core of the algorithm, so it has to come first. I'm going with B.
upvoted 0 times
...
Arlyne
2 months ago
Declare variable Diff. Gotta start somewhere, right?
upvoted 0 times
...
Peggie
2 months ago
Okay, I think I've got it. The first step has to be declaring the variable Diff, since you need to have that variable defined before you can set it or output it. I'll go with option D.
upvoted 0 times
...
Merilyn
2 months ago
The first step is to declare the variable Diff.
upvoted 0 times
...
Meghan
3 months ago
Declare variable Diff. Ah, the classic "let's set up our variables" move.
upvoted 0 times
...
Stephaine
3 months ago
No, we should output Diff after setting it.
upvoted 0 times
...
Maxima
3 months ago
Hmm, I'm a bit confused. The steps are given in no particular order, so I'll need to think through the logical flow to determine the first step. Let me re-read this a few times.
upvoted 0 times
...
Hayley
3 months ago
This looks like a pretty straightforward algorithm question. I'd start by carefully reading through the steps and thinking about the logical order they need to be executed in.
upvoted 0 times
...

Save Cancel