Advertisement
GeorgiLukanov87

02. Command Center Python Fundamentals Exam - 24 March2019 100/100

Jul 19th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. # 02. Command Center Python Fundamentals Exam - 24 March2019 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1590#1
  3.  
  4.  
  5. def is_index_valid(some_list: list, some_index: int):
  6.     if 0 <= some_index < len(some_list):
  7.         return True
  8.     return False
  9.  
  10.  
  11. data = list(map(int, input().split(' ')))
  12. command = input()
  13.  
  14. commands_counter = 0
  15. while not command == 'end':
  16.     details = command.split(' ')
  17.  
  18.     if 'swap' in details:
  19.         index1 = int(details[1])
  20.         index2 = int(details[2])
  21.         if not is_index_valid(data, index1) or not is_index_valid(data, index2):
  22.             print(data)
  23.             commands_counter += 1
  24.         else:
  25.             data[index1], data[index2] = data[index2], data[index1]
  26.             print(data)
  27.             commands_counter += 1
  28.  
  29.     elif 'enumerate_list' in details:
  30.         enumerate_list = []
  31.         for index, el in enumerate(data):
  32.             to_print = f"({index}, {el})".strip()
  33.             enumerate_list.append(to_print)
  34.         print(f"[{', '.join(enumerate_list)}]")
  35.         commands_counter += 1
  36.  
  37.     elif 'max' in details:
  38.         print(max(data))
  39.         commands_counter += 1
  40.     elif 'min' in details:
  41.         print(min(data))
  42.         commands_counter += 1
  43.  
  44.     elif 'get_divisible by' in ' '.join(details):
  45.         commands_counter += 1
  46.         divisor = int(details[2])
  47.         divisible = []
  48.         for el in data:
  49.             if el % divisor == 0:
  50.                 divisible.append(el)
  51.         print(divisible)
  52.  
  53.     command = input()
  54.  
  55. print(commands_counter)
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement