Min() function


#1

why does the function min() gives output -1 if i give arguments as( -1,0,-1.0)?


#2

what did you expect instead then?

lets assume this function has a very basic algorithm implemented:

def my_min(*args):
    smallest = args[0]
    for arg in args:
        if arg < smallest:
            smallest = arg
            
    return smallest

print my_min(-1.0,0,-1)
print min(-1.0,0,-1)

my function seems reasonable accurate, if we put -1.0 first, this is the output for both my_min and min

-1.0 and -1 are equal, so it fails the arg < smallest condition


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.