Absolute Value

Problem Statement

Given an integer value, positive or negative, find its absolute value.

Absolute value is defined as the magnitude of the given value, ignoring the sign.

Input

The first line of input contains an integer value n, where n can be negative or positive or zero.

Output

Print the absolute value of given integer.

As is

The boilerplate code is already there to read the input from user as an integer into a variable, in the main() function. Also it calls the absolute_value() function, and prints the returned value. Do not edit this code.

To do ✍

absolute_value() has one parameter: num which is an integer value. Write code inside the function body to compute the absolute value of given integer value, and return the absolute value.

Example 1

Test input

-52

Test output

52

Explanation

52 is the magnitude of the value -52.

Example 2

Test input

48

Test output

48

Explanation

48 is the magnitude of the value 48.

Useful References

Python Program

# Complete the following function
# Return the absolute value
def absolute_value(n):



# Boilerplate code - Do not edit the following
def main():
    n = int(input())
    print(absolute_value(n))

if __name__ == "__main__":
    main()

Test case 1

0
0

Test case 2

-100
100

Test case 3

54
54
# Complete the following function
# Return the absolute value
def absolute_value(n):
    return abs(n)

# Boilerplate code - Do not edit the following
def main():
    n = int(input())
    print(absolute_value(n))

if __name__ == "__main__":
    main()
show answer
main.py
⏵︎ Run Tests
Reset
Download
×
Code copied to clipboard successfully 👍