Reputation: 15
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:
For example:
> 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 I can't work my head around it..
Upvotes: 0
Views: 171
Reputation: 6526
As already indicated in a previous answer, you just have to add a return
statement in your function. Additionnally, you can use packing to simplify and manage a variable number of arguments. Finally it results in a one-lined and easy-to-read function, as follows:
def do_tuple(*args):
return (max(args), min(args), sum(args))
print(do_tuple(5, 3, -1)) # (5, -1, 7)
Upvotes: 2
Reputation: 265
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))
Upvotes: 2