diff --git a/class_materials/exercises/particle_update_position.ipynb b/class_materials/exercises/particle_update_position.ipynb index b3d829a..3e67429 100644 --- a/class_materials/exercises/particle_update_position.ipynb +++ b/class_materials/exercises/particle_update_position.ipynb @@ -52,15 +52,19 @@ ], "source": [ "class Particle:\n", - " def __init__(self, mass, velocity):\n", + " def __init__(self, mass, velocity, position = 0):\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", - "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", + "print(particle.momentum())\n" ] }, { @@ -84,10 +88,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "8.28" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "particle.update_position(0.1)\n", + "particle.position" + ] }, { "cell_type": "code", @@ -118,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.13.6" }, "toc": { "nav_menu": { @@ -142,5 +160,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }