Simple Array Sum

Sort by

recency

|

3414 Discussions

|

  • + 0 comments

    Python Code:

    def simpleArraySum(ar):

    # Write your code here
    ar_sum = 0
    for i in ar:
        ar_sum += i
    return ar_sum
    
  • + 0 comments

    This problem is a great way to practice working with arrays and basic loops in programming! windaddy sign up

  • + 0 comments

    What's wrong in my code?

    def sumArray(ar = []): n = int(input("Cuantos numeros deseas que contenga la lista?: "))

    for i in range(n):
        if n < 0 or n >=1000:
            print("Número no valido, ingresa valores entre 0 - 1000")
            n = int(input("Cuantos numeros deseas que contenga la lista?: "))
        else:
            for j in range(n):
                elements = int(input("Ingresa los elementos de la lista: "))
                ar.append(elements)
                sum_list = sum(ar,0)
            return sum_list
    
  • + 0 comments
    # Python version
    
    def simpleArraySum(ar):
        return sum(ar)
    
  • + 0 comments

    The Simple Array Sum problem involves summing up all the elements in an array. Here's a simple way to do it in Python:

    This function takes an array arr and returns the sum of all its elements. The built-in sum() function in Python makes it straightforward to calculate.