On Beyond Strings


#1


I don't quite understand why the min(args) print out -10 instead of -5 when the smallest number is -5.


def biggest_number(*args):
    print max(args)
    return max(args)
    
def smallest_number(*args):
    print min(args)
    return min(args)

def distance_from_zero(arg):
    print abs(arg)
    return abs(arg)


biggest_number(-10, -5, 5, 10)
smallest_number(-5,-10, 5, 10)
distance_from_zero(-10)

output:
10
-10
10
None


#2

Negative numbers:

a number have high absolute value is low .

-2 is bigger than -3,
-3 is greater than -100.
same as -5 is greater than -10.


#3

To visualize...

The graph of y = x is a straight line with slope, m = 1, passing through the origin and rising to the right.

               y
               ^           >
               |         *
               |       *
               |     *
               |   *
               | *
 <-------------*-------------> x
             * |
           *   |
         *     |
       *       |
     *         |
   <           v

The graph of y = |x| consists of two rays that both start at the origin. The slope of the graph in Q2 is -1.

               y
   <           ^           >
     *         |         *
       *       |       *
         *     |     *
           *   |   *
             * | *
 <-------------*-------------> x
               |
               |
               |
               |
               |
               v

The thing that messes with everyone's head is that in the first graph, y gets smaller as x gets smaller. In the second graph, y gets bigger as x gets smaller., when x < 0.


#4

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