{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Object Oriented Programming\n", "## Homework Assignment\n", "\n", "####Problem 1\n", "Fill in the Line class methods to accept coordinate as a pair of tuples and return the slope and distance of the line." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "class Line(object):\n", " \n", " def __init__(self,coor1,coor2):\n", " pass\n", " \n", " def distance(self):\n", " pass\n", " \n", " def slope(self):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# EXAMPLE OUTPUT\n", "\n", "coordinate1 = (3,2)\n", "coordinate2 = (8,10)\n", "\n", "li = Line(coordinate1,coordinate2)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "9.433981132056603" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "li.distance()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1.6" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "li.slope()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "________\n", "####Problem 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fill in the class " ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [], "source": [ "class Cylinder(object):\n", " \n", " def __init__(self,height=1,radius=1):\n", " pass\n", " \n", " def volume(self):\n", " pass\n", " \n", " def surface_area(self):\n", " pass" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# EXAMPLE OUTPUT\n", "c = Cylinder(2,3)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "56.52" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.volume()" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "94.2" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.surface_area()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }