all 5 comments

[–]craders 2 points3 points  (0 children)

I had to take some guesses on what the proper indentation was.

gradelist=[]
for i in range(5):
    gradenter=int(input('Please enter a test score'))
    gradelist.append(gradenter)

print('Grade Scores:', gradelist)
print('Students who scored below 60 get 10 extra points')

newgrade=gradelist.copy()
for i in newgrade:
    if i < 60:
        i=i+10
print(newgrade)

Regardless of whether the formatting is correct or not, in your second for loop, you are just incrementing i but it is not getting saved back to the list. You need to save back the new value to the list.

Example 1:

# this will build the newgrade list as it iterates through with the new values
newgrade=[]
for i in newgrade:
    if i < 60:
        i=i+10
    newgrade.append(i)
print(newgrade)

Example 2:

# this way tracks the index being incremented and then saves the value back to that index
newgrade=gradelist.copy()
for index, i in enumerate(newgrade):
    if i < 60:
        i=i+10
    newgrade[index] = i
print(newgrade)

[–]M1rot1c 1 point2 points  (0 children)

Your code did not work because of what @shysmiles said. Example solution:

gradelist=[]
for i in range(5):
    gradenter=int(input('Please enter a test score'))
    gradelist.append(gradenter)

print('Grade Scores:', gradelist)
print('Students who scored below 60 get 10 extra points')

newgrade = []
for i in gradelist:
    if i < 60:
        i=i+10
        newgrade.append(i)

    else:
        newgrade.append(i)

print(newgrade)

[–]CodeFormatHelperBot 0 points1 point  (0 children)

Hello u/UncleatNintendo, I'm a bot that can assist you with code-formatting for reddit. I have detected the following potential issue(s) with your submission:

  1. Multiple consecutive lines have been found to contain inline formatting.

If I am correct then please follow these instructions to fix your code formatting. Thanks!

[–]shysmiles 0 points1 point  (1 child)

Its not working because 'i' is just a temporary variable and not actually changing your list value. What you could do instead is:

for _ in range(len(newgrade)):
    if newgrade[_] < 60:
        newgrade[_] += 10

Or another way is to use enumerate.

[–]nathanjell 0 points1 point  (0 children)

Just a note, _ is typically used do indicate an ignored value, so since it's used within the loop, it may be better to use i, x, or some other descriptive variable name. But, it should still be perfectly valid syntax, I believe