tags:
- code
topic: Absolute
difficulty: Easy
link: https://www.codewars.com/kata/55685cd7ad70877c23000102/solutions/python
date: 2023-10-20
Problem
You are given a number and have to make it negative. However, if the number is already negative (or is 0), nothing needs to occur.
make_negative(1); # return -1
make_negative(-5); # return -5
make_negative(0); # return 0
def make_negative( number ):
return (number if number < 0 else -number)
def make_negative( number ):
return -abs(number)
|x|
in mathematics; returning the (positive) absolute value regardless of existing sign.