Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

1st element must be the smallest parameter
2nd element must be the biggest parameter
3rd element is the sum of parameters

Example print:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading