Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 02. Command Center Python Fundamentals Exam - 24 March2019 100/100
- # https://judge.softuni.org/Contests/Practice/Index/1590#1
- def is_index_valid(some_list: list, some_index: int):
- if 0 <= some_index < len(some_list):
- return True
- return False
- data = list(map(int, input().split(' ')))
- command = input()
- commands_counter = 0
- while not command == 'end':
- details = command.split(' ')
- if 'swap' in details:
- index1 = int(details[1])
- index2 = int(details[2])
- if not is_index_valid(data, index1) or not is_index_valid(data, index2):
- print(data)
- commands_counter += 1
- else:
- data[index1], data[index2] = data[index2], data[index1]
- print(data)
- commands_counter += 1
- elif 'enumerate_list' in details:
- enumerate_list = []
- for index, el in enumerate(data):
- to_print = f"({index}, {el})".strip()
- enumerate_list.append(to_print)
- print(f"[{', '.join(enumerate_list)}]")
- commands_counter += 1
- elif 'max' in details:
- print(max(data))
- commands_counter += 1
- elif 'min' in details:
- print(min(data))
- commands_counter += 1
- elif 'get_divisible by' in ' '.join(details):
- commands_counter += 1
- divisor = int(details[2])
- divisible = []
- for el in data:
- if el % divisor == 0:
- divisible.append(el)
- print(divisible)
- command = input()
- print(commands_counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement