简体   繁体   English

如何在Python上启动程序?

[英]How to start a program on Python?

I'm doing a project on projectile motion where I have to create a program that given some values, it will give several values. 我正在做一个关于弹丸运动的项目,我必须创建一个给出一些值的程序,它将给出几个值。 I haven't finished it yet, but I wish to test it, but I have very little knowledge on how to run my programs. 我还没有完成它,但是我想对其进行测试,但是我对如何运行程序的知识很少。 I created a file on Notepad++ with some of my code, but every time I try to run it, it says: 我使用一些代码在Notepad ++上创建了一个文件,但是每次尝试运行该文件时,都会显示:

Traceback (most recent call last): 追溯(最近一次通话):

File <"stdin">, line 1, in 文件<“ stdin”>,第1行,在

ImportError: no module named py ImportError:没有名为py的模块

The thing is, I don't see anywhere how to run my programs on Python using Notepad++ so I am confused as to what I have to do. 问题是,我在任何地方都看不到如何使用Notepad ++在Python上运行程序,因此我对必须执行的操作感到困惑。 I am using the command prompt to run my program. 我正在使用命令提示符运行程序。 I will post what I have so far of my project because maybe it's a problem of what I have written. 我将发布我到目前为止的项目,因为这可能是我所写内容的问题。 This is what I have so far: 这是我到目前为止的内容:

"""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)))
  • Store the program in a file named "projectile.py" 将程序存储在名为“ projectile.py”的文件中
  • Install Python 3 and NumPy . 安装Python 3NumPy
  • Then open console, navigate to the folder containing the file 然后打开控制台,导航到包含文件的文件夹
  • Invoke 调用

    python3 projectile.py python3 projectile.py

I am assuming you are on Windows, for the reference good ol' command prompt. 我假设您在Windows上,以获取参考“好”命令提示符。 Be sure you have Python installed, then navigate to the folder you have your Python script stored. 确保已安装Python,然后导航到存储Python脚本的文件夹。 Shift right-click on the folder and select "Open command window here". 在文件夹上单击鼠标右键,然后选择“在此处打开命令窗口”。 A CMD window should appear. 应显示一个CMD窗口。 Now just type 现在只要输入

python name_of_your_python_file.py

And you should see the output. 并且您应该看到输出。 As for the ImportError you posted, be sure to have all dependencies installed. 至于您发布的ImportError,请确保已安装所有依赖项。 (Numpy) (脾气暴躁)

If you are determined to use Notepad++ as your development environment, read here for more information on running those Python scripts direct from notepad++ 如果确定要使用Notepad ++作为开发环境,请阅读此处以获取有关直接从notepad ++运行这些Python脚本的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM