0

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:

Traceback (most recent call last):

File <"stdin">, line 1, in

ImportError: no module named 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. 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)))
Amadan
  • 191,408
  • 23
  • 240
  • 301
George
  • 135
  • 5
  • Your program works without an error. (I don't know if it does the right thing, as I don't know what it should do and it is not printing anything. But it's doing *something* without an error). How exactly are you starting your program? (i.e. which exact command?) – Amadan Dec 09 '14 at 02:29
  • How, exactly, are you trying to run the program? What's its name, for example? Are you running from the command line, or from a file window, or does Notepad have some gadget that's supposed to run programs? – Lee Daniel Crocker Dec 09 '14 at 02:32
  • I was running python and said 'import file_name.py – George Dec 09 '14 at 02:47
  • That should be `import file_name`; that is, drop the `.py` in an import statement. – msw Dec 09 '14 at 02:50
  • Also I really suggest you to download some free IDE's like JetBrains PyCharm Community edition (which is my favourite one), since it really makes running and debugging of your programs easier. – Amar Kalabić Dec 09 '14 at 11:17

2 Answers2

0
  • Store the program in a file named "projectile.py"
  • Install Python 3 and NumPy.
  • Then open console, navigate to the folder containing the file
  • Invoke

    python3 projectile.py

Basilevs
  • 22,440
  • 15
  • 57
  • 102
0

I am assuming you are on Windows, for the reference good ol' command prompt. Be sure you have Python installed, then navigate to the folder you have your Python script stored. Shift right-click on the folder and select "Open command window here". A CMD window should appear. 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. (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++

Community
  • 1
  • 1
Jacob Bridges
  • 725
  • 2
  • 8
  • 16