Wednesday, February 16, 2011

Exercising Python3

Today lesson was hard to understand because all this code:
a = 23
b = -23
 
def absolute_value(n):
    if n < 0:
        n = -n
    return n
 
if absolute_value(a) == absolute_value(b):
    print("The absolute values of", a, "and", b, "are equal")
else:
    print("The absolute values of", a, "and", b, "are different")
got to the conclusion of this:
The absolute values of 23 and -23 are equal


I understand some parts but some parts of this tutorial code it just seem complicated for example
def absolute_value(n):
    if n < 0:
        n = -n
    return n
  I don't know really understand what does that have to do in all this problem.

No comments:

Post a Comment