CHATGPT AI
deltasigma
(1,2,3)
§ Output
> ['1.0']
§ Markdown
## Exercise 3.2
Write a function that takes as input three lists of numbers of the same length and returns the list whose values are the averages of the corresponding lists. For example,
```python
average_list([1,2,3],[4,5,6],[7,8,9])
```
should return ```[4,5,6]```.
§ Code
def average_list(list1, list2, list3): # define function with 3 input parameters: list1 , list2 and list3
# create an empty list to store the results # initialize empty list to store results
average_list = [] # create an empty list to store the results
for i in range (len(list1)): # loop over each element in each of the 3 lists
average = (list1[i] + list2[i] + list3[i])/3 # calculate average for each element in each of the 3 lists
average_list.append(average) # append result to empty list created above
return average_list # return result from function
average_list([1,2,3],[4,5,6],[7,8,9]) # call function with 3 input parameters: [1 , 2 , 3], [4 , 5 , 6], [7 , 8 , 9]
# expected output : [4.0 , 5.0 , 6.0]
§ END OF DOC
§ Output
> ['1.0']
§ Markdown
## Exercise 3.2
Write a function that takes as input three lists of numbers of the same length and returns the list whose values are the averages of the corresponding lists. For example,
```python
average_list([1,2,3],[4,5,6],[7,8,9])
```
should return ```[4,5,6]```.
§ Code
def average_list(list1, list2, list3): # define function with 3 input parameters: list1 , list2 and list3
# create an empty list to store the results # initialize empty list to store results
average_list = [] # create an empty list to store the results
for i in range (len(list1)): # loop over each element in each of the 3 lists
average = (list1[i] + list2[i] + list3[i])/3 # calculate average for each element in each of the 3 lists
average_list.append(average) # append result to empty list created above
return average_list # return result from function
average_list([1,2,3],[4,5,6],[7,8,9]) # call function with 3 input parameters: [1 , 2 , 3], [4 , 5 , 6], [7 , 8 , 9]
# expected output : [4.0 , 5.0 , 6.0]
§ END OF DOC
(1,2,3)
§ Output
> ['1.0']
§ Markdown
## Exercise 3.2
Write a function that takes as input three lists of numbers of the same length and returns the list whose values are the averages of the corresponding lists. For example,
```python
average_list([1,2,3],[4,5,6],[7,8,9])
```
should return ```[4,5,6]```.
§ Code
def average_list(list1, list2, list3): # define function with 3 input parameters: list1 , list2 and list3
# create an empty list to store the results # initialize empty list to store results
average_list = [] # create an empty list to store the results
for i in range (len(list1)): # loop over each element in each of the 3 lists
average = (list1[i] + list2[i] + list3[i])/3 # calculate average for each element in each of the 3 lists
average_list.append(average) # append result to empty list created above
return average_list # return result from function
average_list([1,2,3],[4,5,6],[7,8,9]) # call function with 3 input parameters: [1 , 2 , 3], [4 , 5 , 6], [7 , 8 , 9]
# expected output : [4.0 , 5.0 , 6.0]
§ END OF DOC
0 Comments & Tags
0 المشاركات
1 مشاهدة