Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- numbers_for_manipulating = list(map(int, input().split()))
- command = input()
- while command != "end":
- current_command = command.split()[0]
- if current_command == "exchange":
- split_index = int(command.split()[1])
- if split_index >= len(numbers_for_manipulating) or split_index < 0:
- print("Invalid index")
- else:
- numbers_for_manipulating = numbers_for_manipulating[split_index+1:] + numbers_for_manipulating[:split_index+1]
- elif current_command == "max":
- odd_or_even = command.split()[1]
- max_num = "No matches"
- if odd_or_even == "odd":
- if odd_or_even == "odd":
- if [x for x in numbers_for_manipulating if x % 2 != 0]:
- for index, data in enumerate(numbers_for_manipulating):
- if data == max([x for x in numbers_for_manipulating if x % 2 != 0]):
- max_num = index
- elif odd_or_even == "even":
- if [x for x in numbers_for_manipulating if x % 2 == 0]:
- for index, data in enumerate(numbers_for_manipulating):
- if data == max([x for x in numbers_for_manipulating if x % 2 == 0]):
- max_num = index
- print(max_num)
- elif current_command == "min":
- odd_or_even = command.split()[1]
- min_num = "No matches"
- if odd_or_even == "odd":
- if [x for x in numbers_for_manipulating if x % 2 != 0]:
- for index, data in enumerate(numbers_for_manipulating):
- if data == min([x for x in numbers_for_manipulating if x % 2 != 0]):
- min_num = index
- elif odd_or_even == "even":
- if [x for x in numbers_for_manipulating if x % 2 == 0]:
- for index, data in enumerate(numbers_for_manipulating):
- if data == min([x for x in numbers_for_manipulating if x % 2 == 0]):
- min_num = index
- print(min_num)
- elif current_command == "first" or current_command == "last":
- count = int(command.split()[1])
- if count <= len(numbers_for_manipulating):
- if command.split()[2] == "even" and current_command == "first":
- print([x for x in numbers_for_manipulating if x % 2 == 0][:count])
- elif command.split()[2] == "odd" and current_command == "first":
- print([x for x in numbers_for_manipulating if x % 2 != 0][:count])
- elif command.split()[2] == "even" and current_command == "last":
- print(list(reversed([x for x in reversed(numbers_for_manipulating) if x % 2 == 0][:count])))
- elif command.split()[2] == "odd" and current_command == "last":
- print(list(reversed([x for x in reversed(numbers_for_manipulating) if x % 2 != 0][:count])))
- else:
- print("Invalid count")
- command = input()
- print(numbers_for_manipulating)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement