{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Functions and Methods Homework \n", "\n", "Complete the following questions:\n", "____\n", "**Write a function that computes the volume of a sphere given its radius.**" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def vol(rad):\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "**Write a function that checks whether a number is in a given range (Inclusive of high and low)**" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def ran_check(num,low,high):\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you only wanted to return a boolean:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def ran_bool(num,low,high):\n", " pass" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ran_bool(3,1,10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "____\n", "**Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters.**\n", "\n", " Sample String : 'Hello Mr. Rogers, how are you this fine Tuesday?'\n", " Expected Output : \n", " No. of Upper case characters : 4\n", " No. of Lower case Characters : 33\n", "\n", "If you feel ambitious, explore the Collections module to solve this problem!" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def up_low(s):\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "____\n", "**Write a Python function that takes a list and returns a new list with unique elements of the first list.**\n", "\n", " Sample List : [1,1,1,1,2,2,3,3,3,3,4,5]\n", " Unique List : [1, 2, 3, 4, 5]" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def unique_list(l):\n", " pass" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 4, 5]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "unique_list([1,1,1,1,2,2,3,3,3,3,4,5])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "____\n", "**Write a Python function to multiply all the numbers in a list.**\n", "\n", " Sample List : [1, 2, 3, -4]\n", " Expected Output : -24" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def multiply(numbers): \n", " pass" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "-24" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multiply([1,2,3,-4])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "____\n", "**Write a Python function that checks whether a passed string is palindrome or not.**\n", "\n", "Note: A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def palindrome(s):\n", " pass" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "palindrome('helleh')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "____\n", "**Hard**:\n", "\n", "Write a Python function to check whether a string is pangram or not.\n", "\n", " Note : Pangrams are words or sentences containing every letter of the alphabet at least once.\n", " For example : \"The quick brown fox jumps over the lazy dog\"\n", "\n", "Hint: Look at the string module" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import string\n", "\n", "def ispangram(str1, alphabet=string.ascii_lowercase): \n", " pass" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ispangram(\"The quick brown fox jumps over the lazy dog\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'abcdefghijklmnopqrstuvwxyz'" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "string.ascii_lowercase" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "####**Great Job!**" ] } ], "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 }