Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- numbers = list(map(int, input().split()))
- def change_value(idx, value):
- if 0 <= idx < len(numbers):
- for i in range(0, len(numbers)):
- if i == idx:
- numbers[i] = value
- def sum_positives():
- result_of_positive_nums = 0
- for num in numbers:
- if num > 0:
- result_of_positive_nums += num
- print(result_of_positive_nums)
- def sum_negatives():
- result_of_negative_nums = 0
- for num in numbers:
- if num < 0:
- result_of_negative_nums += num
- print(result_of_negative_nums)
- def switch_numbers(index):
- if 0 <= index < len(numbers):
- for i in range(0, len(numbers)):
- if i == index:
- numbers[i] = -numbers[i]
- while True:
- command = input()
- if command == "End":
- break
- tokens = command.split()
- action = tokens[0]
- if action == "Switch":
- index = int(tokens[1])
- switch_numbers(index)
- elif action == "Change":
- idx = int(tokens[1])
- value = int(tokens[2])
- change_value(idx, value)
- elif action == "Sum" and tokens[1] == "Negative":
- sum_negatives()
- elif action == "Sum" and tokens[1] == "Positive":
- sum_positives()
- elif action == "Sum" and tokens[1] == "All":
- print(sum(numbers))
- print(" ".join(map(str, [i for i in numbers if i >= 0])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement