Прежде всего, порядок следования операторов:
if condition:
doSomething()
elif anotherCondition:
doSomethingDifferent()
elif anotherAnotherCondition:
doSomethingDifferentAgain()
else: #otherwise - if the above conditions don't satisfy(are not True)
doThis()
Во-вторых,
Цикл for имеет проблему, при которой вы передаете список a в follow_path (), а затем передаете первый второй и третий элементы списка в направлении, расположении и элементе выбора.
def follow_path(a):
for draw in a:
direction(a[0])
location(a[1])
choosetoken(a[2])
def direction(thing):
print("direction " + str(thing))
def location(thing):
print("location " + str(thing))
def choosetoken(thing):
print("choosetoken " + str(thing))
a = [['Start', 'Bottom right', 1],['South', 1, 1], ['North', 3, 4], ['West', 4, 0], ['West', 2, 0], ['South', 3, 4]]
follow_path(a)
Это было задумано? или ты хотел что-то подобное;
def follow_path(a):
for draw in a:
direction(draw[0])
location(draw[1])
choosetoken(draw[2])
def direction(thing):
print("direction " + str(thing))
def location(thing):
print("location " + str(thing))
def choosetoken(thing):
print("choosetoken " + str(thing))
a = [['Start', 'Bottom right', 1],['South', 1, 1], ['North', 3, 4], ['West', 4, 0], ['West', 2, 0], ['South', 3, 4]]
follow_path(a)
Что происходит, вы перебираете список a; и выбор нулевого, первого и второго элемента из каждой итерации.
Итак, первая итерация будет [«Пуск», «Справа внизу», 1], я выбираю ноль, первый и второй; «Пуск», «Внизу справа», 1 соответственно, затем переходите к следующей итерации, которая будет [«Юг», 1, 1], делайте то же самое и т. Д.
Надеюсь, это поможет:)