Sunday, September 27, 2020

how to add negative numbers in list in python

 given_list = [5, 4, 4, 3, 1, -2, -3, -5, -7]

total = 0

i = 0

while(i < len(given_list)):

    if given_list[i] < 0:

        total += given_list[i]

        i += 1

print(total)

No comments:

Post a Comment

What 29 Years Have Taught Me About Life ❤️ | Physical Growth, Mental Strength & Helping Others

https://www.youtube.com/watch?v=sYzTFCn9KlM Hi, namaste Kamu. So, um tomorrow I am going to complete 29 years of age and uh one learning tha...