I’m stuck on an exercise where I should do a function which makes a tuple out of 3 given numbers and returns tuple following these rules:
1st element must be the smallest parameter
2nd element must be the biggest parameter
3rd element is the sum of parameters
Example print:
print(do_tuple(5, 3, -1))
(-1, 5, 7)
What I have so far:
def do_tuple(x: int, y: int, z: int):
tuple_ = (x,y,z)
summ = x + y + z
mini = min(tuple_)
maxi = max(tuple_)
if __name__ == "__main__":
print(do_tuple(5, 3, -1))
I know I should be able to sort and return these values according to the criteria but cant work my head around it..
>Solution :
You need to return the tuple inside your function
def do_tuple(x: int, y: int, z: int):
tuple_ = (x,y,z)
summ = x + y + z
mini = min(tuple_)
maxi = max(tuple_)
return (mini, maxi, summ)
if __name__ == "__main__":
print(do_tuple(5, 3, -1))