Solving this kata from codewars ,any tips/fixing ? (new to python)

Question:

So i have this kata:
In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?

Example:

make_negative(1)   # return -1
make_negative(-5)  # return -5
make_negative(0)   # return 0

and i tried solving it with:

def make_negative(number):
    if number > 0:
        number * -1
    elif number < 0:
        pass
    return number

and the result i get is ( Passed: 2Failed: 1Exit Code: 1 ) the failed one says (42 should equal -42)

Real question is , what did i do wrong ? and if some1 can help me solve this ? ^^

Asked By: Richard

||

Answers:

Can you try this?

def make_negative(num):
    if num > 0:
        return num * (-1)
    elif num < 0: 
        return num
    else:
        return 0
Answered By: han

This Also Works:

if (num > 0){
return num * -1
}else {
return num;
}

or

return num > 0 ? num * -1 : num;
Answered By: Chuka99

Try this

def make_negative( number ):
    if number < 0 or number==0:
        return number
    elif number > 0:
        return (number - (2*number))
Answered By: FantasticCoder
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.