I would like to create a function where one passes a list of numbers and gets back another list where the signs of all numbers are reversed. This is my code:
def reverse_sign_of_nos_in_a_list(list1):
""" This function reverses sign of numbers
in a list and returns a list.
"""
list2 = []
for num in list1 :
if num > 0 :
return list2.append(num * -1)
elif num < 0 :
return list2.append(abs(num))
else :
return list2.append(num)
print (reverse_sign_of_nos_in_a_list([1,2,3,-1,-2,-3,0]))
The above code shows None
as the output. What's the issue?