forked from Phys767-Spring17/Particle-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.py
43 lines (33 loc) · 1.19 KB
/
particle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# particle.py
import particle as p
class Particle(object):
"""A particle is a constituent unit of the universe.
Attributes
-----------
c : charge in units of [e]
m: mass in units of [kg]
r: position in units of [meters]
"""
roar = "I am a particle!" # an attribute
# def __init__(self): # this is a constructor, a function that is a method; provides initial conditions
# """Initializes the particle with default values for
# charge c, mass m, and position r.
# """
# self.c = 0
# self.m = 0
# self.r = {'x': 0, 'y': 0, 'z': 0}
def __init__(self, charge, mass, position):
"""Initializes the particles with supplied values for
charge c, mass m, and position r.
"""
self.c = charge
self.m = mass
self.r = position
def hear_me(self): # this is a method
myroar = self.roar + (
" My charge is: " + str(self.c) +
" My mass is: " + str(self.m) +
" My x position is: " + str(self.r['x']) +
" My y position is: " + str(self.r['y']) +
" My z position is: " + str(self.r['z']))
print(myroar)