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