From f333013abf81f4cea49fb04fcd57afa03167a0c4 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Thu, 25 Sep 2025 10:42:16 +0300 Subject: [PATCH] add position as class attribute --- .../exercises/particle_update_position.ipynb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index e668f0d..5b22a19 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -52,17 +52,18 @@ ], "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", + " self.position = position\n", "\n", " def momentum(self):\n", " return self.mass * self.velocity\n", "\n", - " def update_position(self, position, dt):\n", - " return position + self.velocity * dt\n", + " def update_position(self, dt):\n", + " return self.position + self.velocity * dt\n", "\n", - "particle = Particle(mass=2.1, velocity=0.8)\n", + "particle = Particle(mass=2.1, velocity=0.8, position = 8.2)\n", "print(particle.momentum())" ] }, @@ -80,7 +81,7 @@ } ], "source": [ - "position = 8.2\n", + "\n", "new_position = particle.update_position(position, dt=0.1)\n", "print(new_position)" ]