Python Programming Problem Questions

Asked 2 years ago, Updated 2 years ago, 17 views

Number 1

a = [20, -30, 50, 70, -10]

sum = 0

for i in range(len(a)) :

     if a[i] < 0 :

        break

    sum = sum + a[i]   

print(sum)

Number 2

a = [20, -30, 50, 70, -10]

sum = 0

for i in range(len(a)) :

     if a[i] < 0 :

        continue

    sum = sum + a[i]   

print(sum)

python

2022-09-21 09:58

1 Answers

 a = [20, -30, 50, 70, -10]

sum = 0

for i in range(len(a)) :

     if a[i] < 0 :

        sum = sum + a[i]   


print(sum)


2022-09-21 09:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.