【发布时间】:2017-10-13 18:08:29
【问题描述】:
让我先说我对编码还很陌生,所以要温柔。
我一直在写以下内容:
def execute_move(player, house_choice, houses):
next_house=houses[house_choice]
chosen_house=houses[house_choice-1]
chosen_house_seeds=chosen_house[1]
for i in range(chosen_house_seeds):
if player=='P1': # skips the store of the opposite player
if next_house==houses[13]:
next_house_index=houses.index(next_house)
new_nhi=next_house_index+1
next_house=houses[new_nhi]
elif player=='P2':
if next_house==houses[6]:
next_house_index=houses.index(next_house)
new_nhi=next_house_index+1
next_house=houses[new_nhi]
[(next_house[0], (next_house[1]+1)) if x==next_house else x for x in houses]
next_house_index=houses.index(next_house)
new_nhi=next_house_index+1
next_house=houses[new_nhi]
[(chosen_house[0], (chosen_house[1]-chosen_house_seeds)) if x==chosen_house else x for x in houses]
return houses
我的目标是替换列表“houses”中的一些元组,然后返回新的元组列表。
由于某种原因,我稍后在代码中分配调用的 var 仅在打印时生成原始列表。
我认为这可能与'if'语句的缩进或return语句的缩进有关。
非常感谢您的帮助!
【问题讨论】:
标签: python return indentation