Added update position to class #13
1 changed files with 16 additions and 10 deletions
|
@ -17,7 +17,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 12,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2018-07-27T15:05:51.531289Z",
|
||||
|
@ -35,7 +35,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 10,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
|
@ -46,26 +46,32 @@
|
|||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1.6800000000000002\n"
|
||||
"8.28\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"class Particle:\n",
|
||||
" def __init__(self, mass, velocity):\n",
|
||||
" def __init__(self, mass, velocity, position):\n",
|
||||
" self.mass = mass\n",
|
||||
" self.velocity = velocity\n",
|
||||
"\n",
|
||||
" self.position = position\n",
|
||||
" \n",
|
||||
" def momentum(self):\n",
|
||||
" return self.mass * self.velocity\n",
|
||||
"\n",
|
||||
"particle = Particle(mass=2.1, velocity=0.8)\n",
|
||||
"print(particle.momentum())"
|
||||
" def update_position(self, dt):\n",
|
||||
" self.position = self.position + self.velocity * dt\n",
|
||||
"\n",
|
||||
"particle = Particle(mass=2.1, velocity=0.8, position=8.2)\n",
|
||||
"\n",
|
||||
"particle.update_position(0.1)\n",
|
||||
"print(particle.position)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -118,7 +124,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.11"
|
||||
"version": "3.13.6"
|
||||
},
|
||||
"toc": {
|
||||
"nav_menu": {
|
||||
|
@ -142,5 +148,5 @@
|
|||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue