Fontana dot py
Fontana dot py

Reputation: 15

Tuple function that returns certain parameters

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

Answers (2)

Laurent H.
Laurent H.

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

Guillaume BEDOYA
Guillaume BEDOYA

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

Related Questions