Untitled
unknown
python
9 months ago
830 B
15
Indexable
def ZeroSum(myList):
numPairs=0
uniqueList=[]
for i in range(len(myList)):
if myList[i]*-1 in myList and abs(myList[i]) not in uniqueList:
numPairs+=1
uniqueList.append(abs(myList[i]))
return numPairs
def main():
print("Enter a list of integers separated by spaces (e.g., 1 2 3 4):")
user_input = input("> ")
try:
# Convert the input string into a list of integers
numbers = list(map(int, user_input.strip('[]').split(',')))
# Call the function with the list of integers
result = ZeroSum(numbers)
print(f"The result of the ZeroSum is: {result}")
except ValueError:print("Invalid input. Please ensure the format is correct, e.g., [1,10,8,3,2,-2].")
if __name__ == "__main__":
main()Editor is loading...
Leave a Comment