WGU D598 Task 3: Code Explanation & Data Visualization | 2026 Update
with Complete Solutions
Actual Q&A – A+ Guarantee Format | WGU D598 Task 3 – Code Explanation, Python Pandas, SQL, Data
Cleaning, Visualization Best Practices, Charts, Dashboard, Storytelling, Ethics
1. For D598 Task 3, explain this code: total = price * quantity. What does it do?
A) Calculates total cost by multiplying price per item by quantity, assigns result
to variable total
B) Calculates average
C) No calculation
D) Calculates difference
Answer: A
<b>Rationale:</b> Option A correct explanation of multiplication for total.
Option B wrong average requires sum divided by count, not multiplication.
Option C wrong calculation occurs. Option D wrong difference requires
subtraction, not multiplication.
2. Explain code: if age >= 18: print('Adult') else: print('Minor'). What logic?
A) Checks if age 18 or older, if true prints Adult, else prints Minor, selection
control structure
B) Loop logic
C) No logic
D) Always prints Adult
Answer: A
<b>Rationale:</b> Option A correct selection logic explanation. Option B
wrong loop repeats, this branches once. Option C wrong logic exists. Option
D wrong prints Minor when age <18, not always Adult.
3. Explain code: for i in range(5): print(i). What output?
A) Prints numbers 0,1,2,3,4 each on new line, loop iterates 5 times from 0 to 4
inclusive start exclusive end
B) Prints 5 only
C) No output
D) Prints 1 to 5 inclusive
,Answer: A
<b>Rationale:</b> Option A correct range(5) 0-4. Option B wrong prints 5
numbers not just 5. Option C wrong loop produces output. Option D wrong
range(5) 0-4, range(1,6) would print 1-5.
4. What is purpose of comments in code explanation for Task 3?
A) Comments explain purpose, logic, assumptions using # or // or /* */, improve
readability, maintenance, not executed
B) Comments execute code
C) No purpose for comments
D) Comments delete code
Answer: A
<b>Rationale:</b> Option A correct comments purpose and syntax. Option B
wrong comments not executed, ignored by interpreter/compiler. Option C
wrong comments essential for readability. Option D wrong comments explain,
not delete.
5. Explain this Python code for data cleaning: df.dropna(subset=['age']). What
does it do?
A) Drops rows where age column is missing NULL, keeps rows with age
present, subset specifies column to check
B) Drops all rows
C) Keeps only missing rows
D) No cleaning
Answer: A
<b>Rationale:</b> Option A correct dropna subset explanation. Option B
wrong dropna without subset would drop rows with any missing, subset limits
to age column only. Option C wrong dropna drops missing, not keeps only
missing, keeps non-missing. Option D wrong cleaning operation removes
missing rows.
6. Explain code: df['total'] = df['price'] * df['quantity']. What operation in pandas?
A) Vectorized multiplication creates new column total by multiplying price and
quantity columns element-wise for all rows efficiently
B) Loop manually for each row only
, C) No operation
D) Calculates average
Answer: A
<b>Rationale:</b> Option A correct vectorized column operation. Option B
wrong vectorized operation efficient, not manual loop, though loop possible
but slower. Option C wrong operation creates new column. Option D wrong
average requires sum divided by count, not multiplication.
7. For data visualization, when to use bar chart vs line chart?
A) Bar chart compares categorical values (e.g., sales per product category), line
chart shows trend over time (e.g., monthly sales over year)
B) Bar chart shows trend over time only
C) Line chart compares categorical only
D) No difference
Answer: A
<b>Rationale:</b> Option A correct bar vs line use cases. Option B wrong
bar chart compares categories, line chart shows trend over time, though bar
can show time but line better for continuous time. Option C wrong line chart
shows trend over time, bar chart compares categorical. Option D wrong
difference exists.
8. What is data visualization best practice for color use?
A) Use color purposefully: distinct colors for categories, sequential for
continuous, avoid too many colors, consider color blindness, use color to
highlight key insights
B) Use random colors without purpose
C) Use all colors at once
D) No color best practice
Answer: A
<b>Rationale:</b> Option A correct color best practices. Option B wrong
random colors confuse. Option C wrong too many colors clutter. Option D
wrong best practices exist.
with Complete Solutions
Actual Q&A – A+ Guarantee Format | WGU D598 Task 3 – Code Explanation, Python Pandas, SQL, Data
Cleaning, Visualization Best Practices, Charts, Dashboard, Storytelling, Ethics
1. For D598 Task 3, explain this code: total = price * quantity. What does it do?
A) Calculates total cost by multiplying price per item by quantity, assigns result
to variable total
B) Calculates average
C) No calculation
D) Calculates difference
Answer: A
<b>Rationale:</b> Option A correct explanation of multiplication for total.
Option B wrong average requires sum divided by count, not multiplication.
Option C wrong calculation occurs. Option D wrong difference requires
subtraction, not multiplication.
2. Explain code: if age >= 18: print('Adult') else: print('Minor'). What logic?
A) Checks if age 18 or older, if true prints Adult, else prints Minor, selection
control structure
B) Loop logic
C) No logic
D) Always prints Adult
Answer: A
<b>Rationale:</b> Option A correct selection logic explanation. Option B
wrong loop repeats, this branches once. Option C wrong logic exists. Option
D wrong prints Minor when age <18, not always Adult.
3. Explain code: for i in range(5): print(i). What output?
A) Prints numbers 0,1,2,3,4 each on new line, loop iterates 5 times from 0 to 4
inclusive start exclusive end
B) Prints 5 only
C) No output
D) Prints 1 to 5 inclusive
,Answer: A
<b>Rationale:</b> Option A correct range(5) 0-4. Option B wrong prints 5
numbers not just 5. Option C wrong loop produces output. Option D wrong
range(5) 0-4, range(1,6) would print 1-5.
4. What is purpose of comments in code explanation for Task 3?
A) Comments explain purpose, logic, assumptions using # or // or /* */, improve
readability, maintenance, not executed
B) Comments execute code
C) No purpose for comments
D) Comments delete code
Answer: A
<b>Rationale:</b> Option A correct comments purpose and syntax. Option B
wrong comments not executed, ignored by interpreter/compiler. Option C
wrong comments essential for readability. Option D wrong comments explain,
not delete.
5. Explain this Python code for data cleaning: df.dropna(subset=['age']). What
does it do?
A) Drops rows where age column is missing NULL, keeps rows with age
present, subset specifies column to check
B) Drops all rows
C) Keeps only missing rows
D) No cleaning
Answer: A
<b>Rationale:</b> Option A correct dropna subset explanation. Option B
wrong dropna without subset would drop rows with any missing, subset limits
to age column only. Option C wrong dropna drops missing, not keeps only
missing, keeps non-missing. Option D wrong cleaning operation removes
missing rows.
6. Explain code: df['total'] = df['price'] * df['quantity']. What operation in pandas?
A) Vectorized multiplication creates new column total by multiplying price and
quantity columns element-wise for all rows efficiently
B) Loop manually for each row only
, C) No operation
D) Calculates average
Answer: A
<b>Rationale:</b> Option A correct vectorized column operation. Option B
wrong vectorized operation efficient, not manual loop, though loop possible
but slower. Option C wrong operation creates new column. Option D wrong
average requires sum divided by count, not multiplication.
7. For data visualization, when to use bar chart vs line chart?
A) Bar chart compares categorical values (e.g., sales per product category), line
chart shows trend over time (e.g., monthly sales over year)
B) Bar chart shows trend over time only
C) Line chart compares categorical only
D) No difference
Answer: A
<b>Rationale:</b> Option A correct bar vs line use cases. Option B wrong
bar chart compares categories, line chart shows trend over time, though bar
can show time but line better for continuous time. Option C wrong line chart
shows trend over time, bar chart compares categorical. Option D wrong
difference exists.
8. What is data visualization best practice for color use?
A) Use color purposefully: distinct colors for categories, sequential for
continuous, avoid too many colors, consider color blindness, use color to
highlight key insights
B) Use random colors without purpose
C) Use all colors at once
D) No color best practice
Answer: A
<b>Rationale:</b> Option A correct color best practices. Option B wrong
random colors confuse. Option C wrong too many colors clutter. Option D
wrong best practices exist.