Main.AbsoluteValue History

Hide minor edits - Show changes to markup

February 02, 2010, at 01:30 PM MST by 129.82.44.241 -
Added lines 1-23:

(:source lang=python:)

"""Compute the absolute value of a number"""

  1. here is a faulty version of a function for computing the absolute
  2. value of a number.
  3. what is the problem?

def faulty_absolute_value(x):

    if x < 0:
        return -x
    elif x > 0:
        return x
  1. here's a version that does the right thing:

def absolute_value(x) :

    if x < 0 :
        return -x
    else :
        return x

(:sourceend:)