Just curious, but why does this work?


#1


Lesson 15. abs()

I didn't expect this to work, why does it work?

absolute = abs(42)

print absolute


#2

It works because abs() is a built in function that returns the absolute value of a given number.


#3

Yea but It's supposed to be
absolute = abs(-42)

not

absolute = abs(42)


#4

Well that is simply because Codecademy's SCT was testing for absolute to be equal to 42.

If
|42| = 42
and
|-42| = 42
then
|42| = |-42|

The SCT got the result it wanted and accepted your code.


#5

SCT? What's that?

And now that makes sense.

Thanks!!!!
EDIT: I needed to thank you :smiley: :grin:


#6

The SCT or Submission Correctness Test is the lesson checker program behind the exercise.

Good, I'm glad you understand.


#7

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