Challenge: Absolute Value

Test yourself and implement what you have learned so far in this chapter.

Problem statement

You need to create a function absolute which computes the absolute value of a given number.


The input of the function is a number x of type num whose absolute value you want to compute.


The output will be the absolute value of x.

Sample input


Sample output


Test yourself

Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy