- Code: Select all
no=int(input())
list=input()
words=list.split(" ")
total=0
for x in words:
total=total+int(str(abs(x))
example inputs:
6
7 -8 6 9 -3 4
answer should be 37.
So how can I do this?
Thank you very much.
no=int(input())
list=input()
words=list.split(" ")
total=0
for x in words:
total=total+int(str(abs(x))
user_input = input("Enter a list of numbers seperated by spaces: ")
sequence = map(int,user_input.split())
sum_of_abs = sum(abs(number) for number in sequence)
print(sum_of_abs)
no=int(input())
list=input()
words=list.split(" ")
total=0
for x in words:
total=total+abs(int(x))
Users browsing this forum: Majestic-12 [Bot] and 6 guests