## Monday, October 12, 2020

Solution Exercise 205: Python program that transform set to the set of averages #### Exercise 205

Given the following set of numerical tuples:
``E = {(12, 3 , 7 , 11) , (2, 9 , 5 , 13) , (1, 4 ,8)}``
Write a Python program that creates a set F whose elements are (Tuple , average of Tuple). Exemple for the set E cited above, the output must be:
``F =  {((2, 9, 5, 13), 7.25), ((12, 3, 7, 11), 8.25), ((1, 4, 8), 4.333333333333333)}``

#### Solution

``````E = {(12, 3 , 7 , 11) , (2, 9 , 5 , 13) , (1, 4 ,8)}
# creating a function that determines the average of given tuple
def averageTuple(T):
n = len(T)
Sum = 0
for i in range(0 , n):
Sum = Sum + T[i]
average = Sum/n
return average

# initializing the set F
F = set({})
for Tuple in E:
# Testing algorithm
print("The searched set is F = " , F)``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 