我正在做一个关于射弹运动的项目,我必须创建一个给出一些值的程序,它会给出几个值。我还没有完成它,但我希望测试它,但我对如何运行我的程序知之甚少。我在Notepad ++上用我的一些代码创建了一个文件,但每次我尝试运行它时都会说:
追踪(最近一次呼叫最后一次):
文件<" stdin">,第1行,
ImportError:没有名为py
的模块问题是,我没有在任何地方看到如何使用Notepad ++在Python上运行我的程序,所以我很困惑我必须做什么。我正在使用命令提示符来运行我的程序。 我将发布我迄今为止的项目,因为它可能是我写的问题。这就是我到目前为止所做的:
"""Mini-Project about projectile motion."""
USER = ""
USER_ID = ""
import numpy as np
#Define variables for ease of use:
g = 9.81 #gravitational constant
u = (float(raw_input("enter launch_speed: ")))#speed of launch
r = (float(raw_input("enter launch_angle_deg: "))*(np.pi)/180) #angle of launch in radians
n = (float(raw_input("enter num_samples: "))) #number of time divisions
#"t" variable of time
#"x" variable of horizontal distance
#"y" variable of vertical distance
def x(t):
"""function that gives the horizontal position "x" as a function
of time.
"""
return u*(np.cos(r))*t #formula for horizontal displacement
def y(t):
"""function that gives the vertical position "y" as a function of
time.
"""
return u*(np.sin(r))*t - (g/2)*t**2 #formula for vertical displacement
def y(x):
"""function that gives the vertical position "y" as a function of the
horizontal position "x".
"""
return x*(np.tan(r))-(g/2)*(x/(u*np.cos(r)))**2
a = np.arange(1, n+1, dtype=float)
def trajectory(launch_speed, launch_angle_deg , num_samples ):
"""This function gives the values of horizontal x-values, vertical
y-values, and time values, respectively, given the values for initial
launch speed, and the angle at which it is launched, for some given
divisions of time that the object is in the air.
"""
while t <= (u*(np.sin(r))/g): #maximum time given by this formula
t = x/(u*(np.cos(r)))
答案 0 :(得分:0)
答案 1 :(得分:0)
我假设你在Windows上,参考good ol'命令提示符。确保安装了Python,然后导航到存储Python脚本的文件夹。右键单击文件夹,然后选择“在此打开命令窗口”。应出现CMD窗口。现在只需输入
即可python name_of_your_python_file.py
你应该看到输出。至于您发布的ImportError,请务必安装所有依赖项。 (NumPy的)
如果您决定使用Notepad ++作为开发环境,请read here了解有关直接从notepad ++运行这些Python脚本的更多信息