add update_position as a class method

This commit is contained in:
ASPP Student 2025-09-25 10:37:56 +03:00
parent 3d3d3913ef
commit 35d41e1147

View file

@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {
"pycharm": {
"name": "#%%\n"
@ -59,13 +59,16 @@
" def momentum(self):\n",
" return self.mass * self.velocity\n",
"\n",
" def update_position(self, position, dt):\n",
" return position + self.velocity * dt\n",
"\n",
"particle = Particle(mass=2.1, velocity=0.8)\n",
"print(particle.momentum())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@ -78,7 +81,7 @@
],
"source": [
"position = 8.2\n",
"new_position = update_position(particle.velocity, position, dt=0.1)\n",
"new_position = particle.update_position(position, dt=0.1)\n",
"print(new_position)"
]
},
@ -118,7 +121,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.13.6"
},
"toc": {
"nav_menu": {
@ -142,5 +145,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}