当我打印currCalc2时,它显示正确的字符串, 但是当我将其与先前定义的函数一起使用时,它仅输入第一个字母,而不输入完整的附加字符串。
我记得很久以前就遇到过这个问题,不确定如何解决。现在已经拉了我几个小时了。试图将其设置为全局变量,并一直在试图使其正常工作的语法混乱。
def mapLocation(mapInput):
#Final map location
for i in mapInput:
map_xy[0] = mapInput[1]-mapInput[0] #X Coordinate
map_xy[1] = mapInput[2]-mapInput[3] #Y Coordinate
return map_xy
def firstColission(calculateColission):
visitedLocations=[]
inputList = list(calculateColission)
currLocation = (0,0)
currCalc=[]
for x in inputList:
currCalc.append(x)
currCalc2 = ''.join(currCalc)
currLocation=mapLocation(mapInput(currCalc2))#mapInput(currCalc2))
print(currLocation)
visitedLocations.append(currLocation)
我期望输出:[0, 1] [1, 1] [0, 2]
等。但是我得到[0, 1] [0, 1] [0, 1]