Discuss / Python / 请教一个问题

请教一个问题

Topic source

macandle

#1 Created at ... [Delete] [Delete and Lock User]

在本篇的学习过程中:

import math

def move(x, y, step, angle=0): nx = x + step math.cos(angle) ny = y - step math.sin(angle) return nx, ny

以上这部分内容我编辑然后保存为my1st.py

然后打开python3 进入交互模式:

输入:

from my1st import move x,y = move(100,100,60,math.pi / 6) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'math' is not defined

为什么会这样?

x, y = move(100, 100, 60, math.pi / 6)中的 math.pi /6 是啥意思?

math.pi/6是角度,前边出现math未定义是因为你没有导入math import math

为什么 nx = x + step math.cos(angle) ny = y - step math.sin(angle) 中, x 是 + , y 是 - 呢?我转不过弯来


  • 1

Reply