add update_position as a class method #9

Open
mihaelami wants to merge 2 commits from mihaelami/2025-plovdiv-scientific-patterns:exercise1 into main
Showing only changes of commit f333013abf - Show all commits

View file

@ -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)"
]