have a list of numbers such as [1,2,3,4,5...], and I want to calculate (1+2)/2 and for the second, (2+3)/2 and the third, (3+4)/2, and so on. How can I do that?

I would like to sum the first number with the second and divide it by 2, then sum the second with the third and divide by 2, and so on.

Also, how can I sum a list of numbers?

```a = [1, 2, 3, 4, 5, ...]
```

Is it:

```b = sum(a)
print b
```

to get one number?

This is not working for me.

Feb 14, 2022 in Python 939 views

## 1 answer to this question.

Let us take a list of Numbers and generate the sum of the entire list by using sum

```Numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print (sum(Numbers))```

Output

`55`

Well, for sequence part of the question (1+2)/2, (2+3)/2, ..., (9+10)/2
use a generator and the formula (2*i-1)/2.
dot is used here to make the values in decimal or floating point.
The first element needs to be skipped when generating the new list

```Solution = [(2*i-1)/2. for i in Numbers[1:]]
print(Solution)
```

Output

`[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]`
```print (sum(Solution))
```

Output

`49.5`
• 5,480 points

## Sum a list of numbers in Python

So you want (element 0 + element ...READ MORE

+1 vote

## Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

## How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

## Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE