【发布时间】:2021-01-07 03:12:37
【问题描述】:
这是我的代码:
import turtle
def first_index(s):
for i in range(len(s)):
if not (s[i].isdigit()):
return i
return None
def go_to(s):
if s[0] == 'G':
comma_ind = first_index(s)
first_arg = int(s[1:comma_ind])
second_arg = int(s[comma_ind + 1:comma_ind + first_index(s[comma_ind + 1:])])
turtle.goto(first_arg, second_arg)
go_to('G10,10')
有谁知道为什么会出现这个错误?非常感谢您的帮助,谢谢!
【问题讨论】:
-
看起来您的
return None没有缩进到正确的深度。 -
另外,如果你没有从函数返回任何东西,默认情况下它会返回 None。所以你可以删除
return None行。
标签: python string indexing numbers python-turtle