Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Foundations of Programming (Python) (E010) Exam - Topic 2 Question 5 Discussion

Posted by Keva on May 02, 2026 at 11:12 AM

A program needs to update all values in a list by adding 5 to each number. Which for loop structure accomplishes this task?

Suggested Answer: B

To update the actual values inside a list, the program must update each value by itsindex.

The correct code is:

for i in range(len(numbers)):

numbers[i] = numbers[i] + 5

Here, range(len(numbers)) produces valid index positions for the list. The variable i is used to access and update each list element.

Example:

numbers = [10, 20, 30]

for i in range(len(numbers)):

numbers[i] = numbers[i] + 5

print(numbers)

Output:

[15, 25, 35]

Option A does not correctly update the original list:

for number in numbers:

number = number + 5

This changes only the temporary loop variable number, not the actual elements stored inside the list.

Therefore, the correct answer isB.


Get Premium Foundations of Programming (Python) (E010) Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
24 comments · newest first
GE
Gerald 2 days ago
Option C is confusing. It mixes up variable names.
LE
Leonor 7 days ago
Right! Option A won't modify the list directly.
VI
Vicente 12 days ago
Option A seems simpler, but it won't work as intended.
BE
Belen 17 days ago
Agreed! Using range is the best way to access each element.
GA
Galen 23 days ago
I think option B is correct. It updates each index properly.
RE
Renea 28 days ago
Definitely B. It’s the standard way to loop through lists.
NE
Nelida 1 month ago
Option C is confusing. It mixes up the variables.
LA
Lasandra 1 month ago
Yeah, A doesn't modify the list properly.
KE
Kenneth 1 month ago
Option A looks simple, but it won't work as expected.
SH
Shanda 2 months ago
Agreed! Using range is clear and effective.
CR
Cristal 2 months ago
I think option B is the best choice. It updates each index correctly.
CA
Cathrine 2 months ago
B is the only one that actually works for lists.
VE
Verdell 2 months ago
I thought you could just do it in one line, like A!
LI
Linsey 2 months ago
Wait, isn't C just wrong? That doesn't make sense.
AR
Ariel 2 months ago
I think A looks simpler, but B is the right choice.
TI
Timothy 3 months ago
Definitely B, that's how you access list indices.
TA
Tamra 3 months ago
Option C looks wrong to me, but I can't quite remember why. It seems like it’s mixing up the variable names or something.
EL
Elouise 3 months ago
I remember we did something similar in class, and I think using range with the length of the list is the right approach, so B makes sense to me.
DE
Denise 3 months ago
I'm not entirely sure, but I feel like option A might not work since it doesn't actually update the list. It just changes the loop variable.
AL
Aliza 3 months ago
I think option B is correct because it uses the index to access each element in the list. That seems familiar from the practice questions.
DO
Douglass 4 months ago
Option C looks wrong to me, but I can't quite recall why. It just feels off, like it's mixing up the variable names.
BA
Bambi 5 months ago
I remember we did a similar question in class, and I think using range with the length of the list is the right approach, so B sounds good.
CA
Catherin 5 months ago
I'm not entirely sure, but I feel like option A might not work since it doesn't actually modify the list. It just changes the variable.
ZO
Zona 5 months ago
I think option B is correct because it uses the index to access each element in the list. That seems familiar from our practice questions.
0/2000 characters

Save Cancel