Search code examples
pythonpython-3.xlistnumbers

Find negative Numbers in list and change | Python


I want to sort out all Numbers under 0 in a List and add to the numbers under 0 + 500.

import random
from turtle import st

startFrame = random.randint(0, 200)

print(startFrame)

start = []

for i in range(startFrame -125, startFrame):
    
    start.append(i)

print(start)

for Frame in start:
    
    if Frame > 0:
        
        Frame + 500
        
print(start)

Did anyone can find out why its not working?


Solution

  • Just do the following:

    for i in range(len(start)):
        if start[i] < 0:
            start[i] += 500
    print(start)