From 35d41e1147ecc35ee3cf894a1d19652a10164b4e Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Thu, 25 Sep 2025 10:37:56 +0300 Subject: [PATCH] add update_position as a class method --- .../exercises/particle_update_position.ipynb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index b3d829a..e668f0d 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -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 }