Python 3.x 函数中带有返回的意外缩进
错误为:SyntaxError:无效语法Python 3.x 函数中带有返回的意外缩进,python-3.x,Python 3.x,错误为:SyntaxError:无效语法 我已尝试删除返回,但未成功/我正在尝试创建一个函数,该函数检查位置是否空闲(列表中以“.”表示),然后从位置检查动物形状是否未完全就位,如果空闲则返回true 您没有正确索引格栅。 此外,还可以使用格式化程序使代码更具可读性 lion1 =['L',1,[(0,0),(1,0)]] lion2 =['L',2,[(0,0),(0,1),(1,1)]] ########### girafe1
我已尝试删除返回,但未成功/我正在尝试创建一个函数,该函数检查位置是否空闲(列表中以“.”表示),然后从位置检查动物形状是否未完全就位,如果空闲则返回true 您没有正确索引
格栅。
此外,还可以使用格式化程序使代码更具可读性
lion1 =['L',1,[(0,0),(1,0)]]
lion2 =['L',2,[(0,0),(0,1),(1,1)]]
###########
girafe1 =['G',1,[(0,0),(1,0),(1,1)]]
girafe2 =['G',2,[(0,0),(1,0)]]
zebre1 =['Z',1,[(0,0),(1,0)]]
zebre2 =['Z',2,[(0,0),(0,1)]]
elephant1 =['E',1,[(0,0),(0,1)]]
elephant2 =['E',2,[(0,0),(1,0),(0,1)]]
Hippopotam1 =['H',1,[(0,0),(1,0)]]
Hippopotam2 =['H',2,[(0,0),(1,0),(2,0)]]
grille1=[["o","o","o","o","o","o","o","o","o"],["o","o",".",".",".",".",".","o","o"],["o",".",".",".",".",".",".",".","o"],["o",".",".",".",".",".",".",".","o"],["o","o",".",".",".",".",".","o","o"],["o","o","o","o","o","o","o","o","o"]]
Listes_de_tous_animaux=[lion1,lion2,girafe1,girafe2,zebre1,zebre2,elephant1,elephant2,Hippopotam1,Hippopotam2]
def place_libre(x,y,grille,animal):
if grille[x][y]==".":#libre
i=0
temp=[(0,0),(0,0),(0,0)]
for n in range(len(animal[2])):
temp[i]=(x,y)+animal[2][n]
i+=1
if grille[temp[i][0][temp[i][1]]!=".": #depuis position voir si la forme de l'animal correspond a des places vides
return False
print(temp)
return True
place_libre(3,2,grille1,zebre1)
在这一行中,if grill[temp[i][0][temp[i][1]!=”:
看起来您缺少一个括号。它应该是if grill[temp[i][0]][temp[i][1]!=”:
这回答了您的问题吗?谢谢!非常感谢^^
lion1 = ["L", 1, [(0, 0), (1, 0)]]
lion2 = ["L", 2, [(0, 0), (0, 1), (1, 1)]]
###########
girafe1 = ["G", 1, [(0, 0), (1, 0), (1, 1)]]
girafe2 = ["G", 2, [(0, 0), (1, 0)]]
zebre1 = ["Z", 1, [(0, 0), (1, 0)]]
zebre2 = ["Z", 2, [(0, 0), (0, 1)]]
elephant1 = ["E", 1, [(0, 0), (0, 1)]]
elephant2 = ["E", 2, [(0, 0), (1, 0), (0, 1)]]
Hippopotam1 = ["H", 1, [(0, 0), (1, 0)]]
Hippopotam2 = ["H", 2, [(0, 0), (1, 0), (2, 0)]]
grille1 = [
["o", "o", "o", "o", "o", "o", "o", "o", "o"],
["o", "o", ".", ".", ".", ".", ".", "o", "o"],
["o", ".", ".", ".", ".", ".", ".", ".", "o"],
["o", ".", ".", ".", ".", ".", ".", ".", "o"],
["o", "o", ".", ".", ".", ".", ".", "o", "o"],
["o", "o", "o", "o", "o", "o", "o", "o", "o"],
]
Listes_de_tous_animaux = [
lion1,
lion2,
girafe1,
girafe2,
zebre1,
zebre2,
elephant1,
elephant2,
Hippopotam1,
Hippopotam2,
]
def place_libre(x, y, grille, animal):
if grille[x][y] == ".": # libre
i = 0
temp = [(0, 0), (0, 0), (0, 0)]
for n in range(len(animal[2])):
temp[i] = (x, y) + animal[2][n]
i += 1
if grille[temp[i][0]][temp[i][1]] != ".":
return False # depuis position voir si la forme de l'animal correspond a des #places vides
print(temp)
return True
print(place_libre(3, 2, grille1, zebre1))