def average(tup):
""" ugiufh """
total = ((int(tup[0]) + int(tup[1]) + int(tup[2]))/3,
(int(tup[0]) + int(tup[1]) + int(tup[2]))/3,
(int(tup[0]) + int(tup[1]) + int(tup[2]))/3)
return total
I am writing a function to average out three element in a tuple which means if the original tuple = (1, 2, 3) which give me tuple = (2, 2, 2)
My question is there any way to condense what wrote to give me the same answer? If yes, how to condense it?
Thanks
If you are sure you want integer division, you can use
def average(tup):
n = len(tup)
return (sum(int(x) for x in tup) / n,) * n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With