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