Home python Find the sum of numbers in the list

Find the sum of numbers in the list

Author

Date

Category

I want these items to have and brought 13250 (10000 + 2000 + 1250 ).


Answer 1, Authority 100%

the shortest way

print (SUM (LIS))

Answer 2, Authority 43%

That’s how:

import Functools, Operator
LIS = [10000, 2000, 1250]
Print (Operator.add, Lis))

Answer 3, Authority 29%

lis = [10000, 2000, 1250]
Sum = 0.
For i in lis:
  SUM + = I
Print (SUM)

So you can practice in iterative objects


Answer 4, Authority 14%

And so you can practice the Range method:

lis = [10000, 2000, 1250]
Sum = 0.
For i in Range (LEN): # Argument: Stop
  SUM + = LIS [i]
Print (SUM)

So from the end:

lis = [10000, 2000, 1250]
Sum = 0.
For i in Range (LEN (LIS) -1, -1, -1): # Arguments: Start, Stop, Step
  SUM + = LIS [i]
Print (SUM)

Answer 5

  • lis = [10000, 2000, 1250]
    Print (SUM (LIS))
    
  • lis = [10000, 2000, 1250]
    Sum = 0.
    For i in lis:
      SUM + = I
      Print (SUM)
    

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions