def turn_clockwise(point):
all_point = ["N", "E", "S", "W"]
for loop in range[4]:
if all_point[loop] == point:
if loop == 3:
return "N"
else:
return all_point[loop + 1]
来自 PyScripter 上 Python 解释器的消息:
回溯(最近一次调用):
文件“D:\Documents\Pyscripter practice\Chp.6 Exercises - Fruitful functions.py”,第 25 行,在 test_suite()
文件“D:\Documents\Pyscripter practice\Chp.6 Exercises - 丰硕的函数.py”,第 21 行,在 test_suite test(turn_clock("N") == "E")
文件“D:\Documents\Pyscripter practice\Chp.6 练习 - 丰硕的函数.py”,第 5 行,在范围 [4] 中按 turn_clock 进行迭代:
TypeError: 'type' object is not subscriptable
您需要使用()
括号而不是[]
因为range
是我们需要调用的类。
def turn_clockwise(point):
all_point = ["N", "E", "S", "W"]
for loop in range(4):
if all_point[loop] == point:
if loop == 3:
return "N"
else:
return all_point[loop + 1]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句