day2
방법1
def reverse(number):
if number > 0:
number = str(number)
lst = [i for i in number]
lst.reverse()
lst = int("".join(lst))
return lst
else:
number = number * -1
number = str(number)
lst = [i for i in number]
lst.reverse()
lst = "".join(lst)
lst = int(lst) * -1
return lst
방법2
def reverse(number):
if number > 0:
number = str(number)
lst = [i for i in number]
result = []
for i in range(len(lst)-1, -1, -1):
result.append(number[i])
result = int("".join(result))
return result
else:
number = number * -1
number = str(number)
lst = [i for i in number]
result = []
for i in range(len(lst)-1, -1, -1):
result.append(number[i])
result = int("".join(result)) * -1
return result
방법3
def reverse(number):
def solve(numbers):
number = abs(numbers)
str_number = str(number)
result = []
for index, i in enumerate(range(len(str_number)-1, -1, -1)):
a = number // 10**i
b = number % 10**i
result.append(a*(10**index))
number = b
result = sum(result)
if numbers < 0:
return result * -1
else:
return result
return solve(number)
a = reverse(-1234)
print(a)
방법4
def reverse(number):
if number > 0:
num_str=str(number)
text=''
for i in range(len(num_str)):
text = num_str[i] + text
return int(text)
else:
number *= -1
num_str=str(number)
text=''
for i in range(len(num_str)):
text = num_str[i] + text
return int(text)*(-1)