update the class constructor to include update_position method
This commit is contained in:
		
							parent
							
								
									849682b13b
								
							
						
					
					
						commit
						7a3ecc6c44
					
				
					 1 changed files with 37 additions and 16 deletions
				
			
		|  | @ -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": { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue