Никола обнови решението на 22.10.2022 19:58 (преди около 2 години)
+directions = {
+ 'C0FFC0': (-1, 0),
+ '00C000': (1, 0),
+ 'FFFFC0': (0, -1),
+ 'C0C000': (0, 1),
+ 'FFC0C0': (1, 0),
+ 'C00000': (-1, 0),
+ 'C0C0FF': (0, 1),
+ '0000C0': (0, -1),
+ 'FFFFFF': (0, 0)
+}
+
+
+def calculate_final_vector(vct, directs):
+ coord_x = vct[0]
Тук можеш да използваш unpacking:
coord_x, coord_y = vct
+ coord_y = vct[1]
+
+ for direction in directs:
+ direction = direction.upper()
+ if direction == '000000':
+ break
+ else:
+ coord_x += directions[direction][0]
+ coord_y += directions[direction][1]
+
+ return coord_x, coord_y