Решение на Навигация на Piet от Ивана Дончевска

Обратно към всички решения

Към профила на Ивана Дончевска

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def calculate_final_vector(coordinates, list_of_colors):
x, y = coordinates
for color in list_of_colors:
if color == '000000': # If color is black stop and return values of x and y
return x, y
elif color.upper() == 'FFFFFF': # Do nothing
pass
elif color.upper() == '00C000' or color.upper() == 'FFC0C0': # If dark green or light red increase x by 1
x += 1
elif color.upper() == 'C0FFC0' or color.upper() == 'C00000': # If light green or dark red decrease x by 1
x -= 1
elif color.upper() == 'C0C000' or color.upper() == 'C0C0FF': # If dark yellow and light blue increase y by 1
y += 1
elif color.upper() == 'FFFFC0' or color.upper() == '0000C0': # If light yellow and dark blue decrease y by 1
y -= 1
return x, y

Лог от изпълнението

........
----------------------------------------------------------------------
Ran 8 tests in 0.086s

OK

История (2 версии и 1 коментар)

Ивана обнови решението на 21.10.2022 13:16 (преди над 1 година)

+def calculate_final_vector(coordinates, list_of_colors):
+ x = coordinates[0]
+ y = coordinates[1]
+ for color in list_of_colors:
+ if color == '000000': # If color is black stop and return values of x and y
+ return (x, y)
+ elif color.upper() == 'FFFFFF': # Do nothing
+ pass
+ elif color.upper() == '00C000' or color.upper() == 'FFC0C0': # If dark green or light red increase x by 1
+ x += 1
+ elif color.upper() == 'C0FFC0' or color.upper() == 'C00000': # If light green or dark red decrease x by 1
+ x -= 1
+ elif color.upper() == 'C0C000' or color.upper() == 'C0C0FF': # If dark yellow and light blue increase y by 1
+ y += 1
+ elif color.upper() == 'FFFFC0' or color.upper() == '0000C0': # If light yellow and dark blue decrease y by 1
+ y -= 1
+ return (x, y)

Супер, единствената по-meaningful забележка е tuple unpacking-а. Можеш да ползваш просто x, y = coordinates, и върши същата работа, като това как ти си ги взела.
Също така, около return tuple-а не са необходими скоби, но това е дреболия.

Ивана обнови решението на 24.10.2022 20:42 (преди над 1 година)

def calculate_final_vector(coordinates, list_of_colors):
- x = coordinates[0]
- y = coordinates[1]
+ x, y = coordinates
for color in list_of_colors:
if color == '000000': # If color is black stop and return values of x and y
- return (x, y)
+ return x, y
elif color.upper() == 'FFFFFF': # Do nothing
pass
elif color.upper() == '00C000' or color.upper() == 'FFC0C0': # If dark green or light red increase x by 1
x += 1
elif color.upper() == 'C0FFC0' or color.upper() == 'C00000': # If light green or dark red decrease x by 1
x -= 1
elif color.upper() == 'C0C000' or color.upper() == 'C0C0FF': # If dark yellow and light blue increase y by 1
y += 1
elif color.upper() == 'FFFFC0' or color.upper() == '0000C0': # If light yellow and dark blue decrease y by 1
y -= 1
- return (x, y)
+ return x, y