Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Min Max
#1
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?
Reply
#2
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}')
Reply
#3
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.
Reply
#4
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
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?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020