这是检查鼠标点击坐标是否在这些范围内的正确方法吗?
Is this the right way to check if the mouseclick coordinates are within these ranges?
我想检查鼠标点击是否在 400 x 400 的正方形内,这样正确吗?
if turtle.xcor() >= -500 and turtle.xcor()<= -100:
if turtle.ycor() >= -300 and turtle.ycor()<= 100:
print('Goede zet')
else:
print('Foutieve zet')
你的代码完全没问题,但你在这里调用了 turtle.xcor()
和 turtle.ycor()
两次。或者,您可以通过使用以下语法组合您的条件来摆脱 and
,您只需将变量放在要检查的范围内
if -500 <=turtle.xcor()<= -100:
if -300<=turtle.ycor()<= 100:
print('Goede zet')
else:
print('Foutieve zet')
由于您的第二个 if
依赖于第一个 if
,另一个使用单个 if
语句的较短版本是
if (-500 <=turtle.xcor()<= -100) and (-300<=turtle.ycor()<= 100):
print('Goede zet')
else:
print('Foutieve zet')
我想检查鼠标点击是否在 400 x 400 的正方形内,这样正确吗?
if turtle.xcor() >= -500 and turtle.xcor()<= -100:
if turtle.ycor() >= -300 and turtle.ycor()<= 100:
print('Goede zet')
else:
print('Foutieve zet')
你的代码完全没问题,但你在这里调用了 turtle.xcor()
和 turtle.ycor()
两次。或者,您可以通过使用以下语法组合您的条件来摆脱 and
,您只需将变量放在要检查的范围内
if -500 <=turtle.xcor()<= -100:
if -300<=turtle.ycor()<= 100:
print('Goede zet')
else:
print('Foutieve zet')
由于您的第二个 if
依赖于第一个 if
,另一个使用单个 if
语句的较短版本是
if (-500 <=turtle.xcor()<= -100) and (-300<=turtle.ycor()<= 100):
print('Goede zet')
else:
print('Foutieve zet')