How do you write a Python function to calculate and display the average of all the elements in a user defined tuple containing numbers?
Answers
Answered by
4
Answer:
#Python
Explanation:
#lets assume that name of the tuple is ' a'
no_= a.length()
r = 0
for I in range(a):
r += I
avg = r/no_
print("Result : ", avg)
Answered by
1
import random
# populate a tuple
my_tuple = tuple(random.randrange(1, 100 + 1) for x in range(10))
def tup_avg(t):
return sum(t) / len(t)
print(f"average: {tup_avg(my_tuple)}")
Similar questions