From 7a3ecc6c440ad8a0e6ff9da9ec22508c364cc325 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Thu, 29 Aug 2024 10:02:51 +0300 Subject: [PATCH] update the class constructor to include update_position method --- notebooks/01a_Classes.ipynb | 53 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/notebooks/01a_Classes.ipynb b/notebooks/01a_Classes.ipynb index 5e8eb35..ba37b9e 100644 --- a/notebooks/01a_Classes.ipynb +++ b/notebooks/01a_Classes.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-07-27T15:05:51.531289Z", @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-07-27T15:05:51.905235Z", @@ -420,21 +420,13 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "metadata": { "pycharm": { "name": "#%%\n" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "9.0\n" - ] - } - ], + "outputs": [], "source": [ "class Particle:\n", " def __init__(self, mass, velocity):\n", @@ -443,9 +435,38 @@ "\n", " def momentum(self):\n", " return self.mass * self.velocity\n", - "\n", - "particle1 = Particle(10.0, 0.9)\n", - "print(particle1.momentum())" + " \n", + " def update_position(self, position, dt):\n", + " return position + self.velocity * dt" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "particle1 = Particle(10.0, 0.9)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5.5" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "particle1.update_position(1, 5)" ] }, { @@ -562,7 +583,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.12.4" }, "toc": { "nav_menu": {