Main.AbsoluteValue History
Hide minor edits - Show changes to markup
February 02, 2010, at 01:30 PM MST
by -
Added lines 1-23:
(:source lang=python:)
"""Compute the absolute value of a number"""
- here is a faulty version of a function for computing the absolute
- value of a number.
- what is the problem?
def faulty_absolute_value(x):
if x < 0:
return -x
elif x > 0:
return x
- here's a version that does the right thing:
def absolute_value(x) :
if x < 0 :
return -x
else :
return x
(:sourceend:)
