Python Forum
Min Max - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Min Max (/thread-30280.html)



Min Max - 01andy - Oct-13-2020

def find_min(a, b, c):
min(a, b, c)


def find_max(a, b, c):
max(a, b, c)


def main():
a = int(input("Enter number 1:"))
b = int(input("Enter number 2:"))
c = int(input("Enter number 3:"))
find_min(a, b, c)
find_max(a, b, c)
print("The min is", {find_min})
print("The max is", {find_max})


main()
user input is:
Enter number 1:5
Enter number 2:6
Enter number 3:7
and the output I get is:
The min is {<function find_min at 0x10e618b80>}
The max is {<function find_max at 0x1100591f0>}

I don't understand why im getting that and not the minimum value of 5 and the maximum value of 7?


RE: Min Max - Yoriz - Oct-13-2020

In the print statements you have not called the functions, also the functions don't return the values.
see the modified code below
def find_min(a, b, c):
    return min(a, b, c)

def find_max(a, b, c):
    return max(a, b, c)

def main():
    a = int(input("Enter number 1:"))
    b = int(input("Enter number 2:"))
    c = int(input("Enter number 3:"))
    result1 = find_min(a, b, c)
    result2 = find_max(a, b, c)
    print(f'The min is {result1}')
    print(f'The max is {result2}')



RE: Min Max - bowlofred - Oct-13-2020

find_min is a function.  If you  print find_min (note no parentheses), it will give you a short blurb saying it's a function.  That's happening in your print statements.

Before that you call the function (with the parentheses and the arguments) and it runs.  But since you don't assign the return value to anything, the information is lost.  Put that info into a variable and then print the variable.

Or put the full call (with arguments and parentheses) into the print if you don't need the information after printing.


RE: Min Max - Skaperen - Oct-13-2020

yeah, you are printing the function itself.  it could have printed the function's source code, but that might be too much.  a little blurb is more convenient.  i get those often.


RE: Min Max - ndc85430 - Oct-14-2020

Having said all that though, why do you need the functions find_min and find_max? Why would you wrap the calls to min and max inside those other functions, instead of just calling them directly?