Question: I got this homework assignment, cant figure it out.
I need to ask the user how many town names he wants to enter. For example 5.
Then, he enters the 5 town names.
Afterwards, we need to find the average length of the names and show him the names which have less letters than the average length. Thanks for your shared time :)
My code so far:

```
static void Main(string[] args)
{

    int n;
    Console.WriteLine("How many town names would you like to enter:");
    n = int.Parse(Console.ReadLine());
    string[] TownNames = new string[n];
    Console.Clear();
    Console.WriteLine("Enter {0} town names:", n);
    for (int i = 0; i < n; i++)
    {
        Console.Write("Enter number {0}: ", i + 1);
        TownNames[i] = Convert.ToString(Console.ReadLine());
    }

    Console.ReadKey(true);
}

static void Average(double[] TownNames, int n)
{

}

```

Answer: 
**Here you go:**

```
nums = [1,2,3,4]

def add():
    return sum(nums)

def multiple():
    result = 1
    for num in nums:
        result *= num
    return result

print add()
print multiple()

```

**Output:**

```
10
24

```

> 
> If you don't want to use **`sum`** built-in function then you can use this function:
> 
> 
> 

```
def add():
    sum_result = 0
    for num in nums:
        sum_result += num
    return sum_result

```
your code doesn't work correctly because you are only returning the result of the last element in the list

simplest implementation without sum():

```
nums = [1,2,3,4]

def add():
    x = 0
    for i in nums :
        x += i
    return x

def multiple():
    y = 1
    for i in nums :
        y *= i
    return y

print add()
print multiple()

```

note you don't need to use index you can simply iterate the numbers in both

notice that x and y need to be initalized (and for addition its 0 and multiplication its 1)