Алекс обнови решението на 23.10.2022 20:33 (преди около 2 години)
+def calculate_final_vector(vector: tuple, colors: list):
+ x2 = vector[0]
Можеш да unpack-неш:
x2, y2 = vector
А защо въобще x2, а не x?
+ y2 = vector[1]
+
+ for color in colors:
+ # make sure the case is equal everywhere
+ color = color.upper()
+
+ if color == 'FFFFFF': # White
+ continue # do nothing
+ elif color == '000000': # Black
+ break # end
+ elif color == 'C0FFC0': # Light Green
+ x2 = x2 - 1 # right -1
+ elif color == '00C000': # Dark Green
+ x2 = x2 + 1 # right +1
+ elif color == 'FFFFC0': # Light Yellow
+ y2 = y2 - 1 # up -1
+ elif color == 'C0C000': # Dark Yellow
+ y2 = y2 + 1 # up +1
+ elif color == 'FFC0C0': # Light Red
+ x2 = x2 + 1 # left -1 (right +1)
+ elif color == 'C00000': # Dark Red
+ x2 = x2 - 1 # left +1
+ elif color == 'C0C0FF': # Light Blue
+ y2 = y2 + 1 # down +1
+ elif color == '0000C0': # Dark Blue
+ y2 = y2 - 1 # down -1
+
+ final_vector = (x2, y2)
Няма нужда да присвояваш tuple-а към променлива, за да я върнеш. Както няма нужда и от скобите:
return x2, y2
+ return final_vector