{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, simply use `Ctrl`+`Enter` to install the package this notebook needs." ] }, { "cell_type": "code", "collapsed": false, "input": [ "!pip install ipython_doctester\n", "from ipython_doctester import test\n", "import ipython_doctester\n", "ipython_doctester.workshop_name = ''\n", "ipython_doctester.verbose = True" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, fill in your own (first) name and hit `Ctrl`+`Enter`." ] }, { "cell_type": "code", "collapsed": false, "input": [ "ipython_doctester.student_name = ''\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Friday evening exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These exercises cover material from the Midwest Python Workshop Friday Python tutorial.\n", "\n", "If you have any questions, don't hesitate to ask your neighbor or a staff member for help. We're all here to cooperate!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Core exercises: please complete these first\n", "===========================================" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "happyBirthday(name)\n", "===================\n", "\n", "Given a string *name*, return a string of the form \"Happy Birthday !\".\n", "\n", "If you need them, we have Hints (hover over with your mouse to see them) " ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def happyBirthday(name):\n", " '''\n", " >>> happyBirthday('Jessica')\n", " 'Happy Birthday Jessica!'\n", " >>> happyBirthday('Adam')\n", " 'Happy Birthday Adam!'\n", " >>> happyBirthday('Liz')\n", " 'Happy Birthday Liz!'\n", " '''\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "cube(i)\n", "-------\n", "\n", "given a number, return the cube of that number. \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def cube(i):\n", " '''\n", " >>> cube(1)\n", " 1\n", " >>> cube(2)\n", " 8\n", " >>> cube(3)\n", " 27\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "tooLongForTwitter(myString)\n", "---------------------------\n", "\n", "Twitter messages can't be more than 140 characters! Given a string myString, return True if the string is longer that 140 characters, and return False if the string is less than or equal to 140 characters. \n", "\n", ", <=, >=\">Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def tooLongForTwitter(myString):\n", " '''\n", " >>> tooLongForTwitter('The Analytical Engine weaves algebraic patterns, just as the Jacquard loom weaves flowers and leaves.' +\n", " ... '-- Ada Lovelace, the first programmer')\n", " False\n", " >>> tooLongForTwitter('Four score and seven years ago our fathers brought forth on this continent a new nation, ' +\n", " ... 'conceived in liberty, and dedicated to the proposition that all men are created equal.')\n", " True\n", " >>> tooLongForTwitter('They told me computers could only do arithmetic. -- Computer pioneer Grace Hopper')\n", " False\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "multiplyString(myString, numRepetitions))\n", "-----------------------------------------\n", "\n", "Given a string myString and a number numRepetitions, return myString multiplied numRepetitions times. \n", "\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def multiplyString(myString, numRepetitions):\n", " '''\n", " >>> multiplyString('a', 4)\n", " 'aaaa'\n", " >>> multiplyString('Hello', 2)\n", " 'HelloHello'\n", " >>> multiplyString('Python', 3)\n", " 'PythonPythonPython'\n", " '''\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Bonus exercises (Friday night)\n", "==============================\n", "\n", "Try these if you have time!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "checkNickname(nickname, firstname)\n", "----------------------------------\n", "\n", " Given a lowercase string nickname and a lowercase string firstname, return True if nickname is completely a part of firstname. \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def checkNickname(nickname, firstname):\n", " '''\n", " >>> checkNickname('jess', 'jessica')\n", " True\n", " >>> checkNickname('bill', 'william')\n", " False\n", " >>> checkNickname('liz', 'elizabeth')\n", " True\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "greatest(x, y, z)\n", "-----------------\n", "\n", "Given numbers x, y, and z, return the greatest of these three numbers. \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def greatest(x, y, z):\n", " '''\n", " >>> greatest(3, 9, 6)\n", " 9\n", " >>> greatest(0.5, 0.25, 0)\n", " 0.5\n", " >>> greatest(4, 5, 5)\n", " 5\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "End Friday exercises\n", "====================\n", "\n", "Congratulations! Once you've gotten this far, please head back to the workshop wiki to finish the rest of the Friday material." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Saturday morning exercises\n", "==========================\n", "\n", "Wake up your brain with these exercises that review Friday's material.\n", "\n", "If you have any questions, don't hesitate to ask your neighbor or a staff member for help! \n", "\n", "Now is also a great time to review the Friday tutorial material. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "menuSpecials(vegetable, entree)\n", "-------------------------------\n", "\n", "Given a string vegetable and a string entree, return the string \"Today our specials are: <vegetable> and <entree>\". \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def menuSpecials(vegetable, entree):\n", " '''\n", " >>> menuSpecials('asparagus', 'pasta primavera')\n", " 'Today our specials are: asparagus and pasta primavera'\n", " >>> menuSpecials('artichoke', 'steak frites')\n", " 'Today our specials are: artichoke and steak frites'\n", " >>> menuSpecials('kale', 'fondue')\n", " 'Today our specials are: kale and fondue'\n", " '''\n", " " ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "enoughLadybugs(ladybugs, trees)\n", "-------------------------------\n", "\n", "It takes 100 ladybugs to protect 1 tree from aphids. Given an integer ladybugs and an integer trees, return True if you have enough ladybugs to protect the trees, or False if you need to buy more ladybugs.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def enoughLadybugs(ladybugs, trees):\n", " '''\n", " >>> enoughLadybugs(300, 3)\n", " True\n", " >>> enoughLadybugs(300, 4)\n", " False\n", " >>> enoughLadybugs(250, 11)\n", " False\n", " '''\n", " " ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "makeHTML(tag, word)\n", "-------------------\n", "\n", "Web pages use \"HTML markup\" to style their text. For example, \"<i>Test</i>\" causes the string \"Test\" to be displayed in italics. In this example, the \"i\" tag surrounds the string \"Test\" starting with <i> and ending with </i>. Given a string tag and a string word, return the word with HTML tags around it, for example \"<i>Test</i>\". \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def makeHTML(tag, word):\n", " '''\n", " >>> makeHTML('i', 'Test')\n", " 'Test'\n", " >>> makeHTML('b', 'Important!')\n", " 'Important!'\n", " >>> makeHTML('code', 'variable')\n", " 'variable'\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Saturday afternoon exercises\n", "============================\n", "\n", "These exercises will help you review Saturday's material before the afternoon projects.\n", "\n", "If you have any questions, don't hesitate to ask your neighbor or a staff member for help! " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "returnFirstItem(myList)\n", "-----------------------\n", "\n", "Given a list, myList, return the very first (what programmers might call \"zero-th\"), item in that list \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def returnFirstItem(myList):\n", " '''\n", " >>>\n", " >>> returnFirstItem(['a', 'b', 'c'])\n", " 'a'\n", " >>> returnFirstItem([4.5, 72, -1, 6])\n", " 4.5\n", " >>> returnFirstItem(['Hermione', 'Ron', 'Harry'])\n", " 'Hermione'\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "addExclamation(myList)\n", "----------------------\n", "\n", "Given a list myList, add a string \"!\" to the end of the list and return the list \n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def addExclamation(myList):\n", " '''\n", " >>> addExclamation(['alpha', 'beta'])\n", " ['alpha', 'beta', '!']\n", " >>> addExclamation(['Jessica', 'likes', 'ice cream'])\n", " ['Jessica', 'likes', 'ice cream', '!']\n", " >>> addExclamation(['?', '#', '$'])\n", " ['?', '#', '$', '!']\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "findStudent(name, studentList)\n", "------------------------------\n", "\n", "Given a student's name, name, and a list of student names, studentList, return the boolean True if the student name is in the list, and False otherwise.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def findStudent(name, studentList):\n", " '''\n", " >>> findStudent('Wanda', ['Henry', 'Beatrice', 'Wanda', 'Evan'])\n", " True\n", " >>> findStudent('Adam', ['Tanya', 'Alice', 'Sean'])\n", " False\n", " >>> findStudent('Jen', ['Jessica', 'Jessie', 'Jerry', 'Jen'])\n", " True\n", " '''\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "getFirstQWord(wordList)\n", "-----------------------\n", "\n", "Given a list of lowercase words, return the first word that starts with a \"q\". There will always be at least one \"q\" word.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def getFirstQWord(wordList):\n", " '''\n", " >>> getFirstQWord(['quail', 'quetzal', 'quizzical'])\n", " 'quail'\n", " >>> getFirstQWord(['croissant', 'quiche', 'toast'])\n", " 'quiche'\n", " >>> getFirstQWord(['zip', 'blip', 'quip'])\n", " 'quip'\n", " '''\n", " " ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "countFs(phrase)\n", "---------------\n", "\n", "Given a string phrase, return the total number of \"f\"s and \"F\"s in the phrase.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def countFs(phrase):\n", " '''\n", " >>> countFs('Finished files are the result of years of scientific study combined with the experience of years.')\n", " 6\n", " >>> countFs('Four score and seven years ago')\n", " 1\n", " >>> countFs('A man, a plan, a canal - Panama!')\n", " 0\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "startsOrEndsWithZ(myString)\n", "---------------------------\n", "\n", "Given a string myString, return the boolean True if myString starts or ends with 'z' or 'Z', and False if it doesn't.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def startsOrEndsWithZ(myString):\n", " '''\n", " >>> startsOrEndsWithZ('pizzazz')\n", " True\n", " >>> startsOrEndsWithZ('python')\n", " False\n", " >>> startsOrEndsWithZ('zap')\n", " True\n", " '''\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "sumOfAllStrings(stringList)\n", "---------------------------\n", "\n", "Given a list stringList that contains several strings, return the total of the lengths of all of the strings.\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def sumOfAllStrings(stringList):\n", " '''\n", " >>> sumOfAllStrings(['Eleanor', 'Rigby'])\n", " 12\n", " >>> sumOfAllStrings(['Eight', 'Days', 'a', 'Week'])\n", " 14\n", " >>> sumOfAllStrings(['Strawberry', 'Fields', 'Forever'])\n", " 23\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "stretchString(myString, stretch_number)\n", "---------------------------------------\n", "\n", "Given a string myString and an integer stretch_number, return a string in which each character of the original string is repeated stretch_number times.\n", " \n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def stretchString(myString, stretch_number):\n", " '''\n", " >>> stretchString('banana', 2)\n", " 'bbaannaannaa'\n", " >>> stretchString('apple', 3)\n", " 'aaappppppllleee'\n", " >>> stretchString('fig', 4)\n", " 'ffffiiiigggg'\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "squaresList(numberList)\n", "-----------------------\n", "\n", "Given a list of numbers numberList, return a list containing the squares of each of the numbers in numberList in the order in which they appeared in numberList.\n", " \n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def squaresList(numberList):\n", " '''\n", " >>> squaresList([1, 2, 3])\n", " [1, 4, 9]\n", " >>> squaresList([4, 0])\n", " [16, 0]\n", " >>> squaresList([12, 9, 6, 3])\n", " [144, 81, 36, 9]\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "removeVowels(myString)\n", "----------------------\n", "\n", "Given a lower-case string myString, return that string with all of the vowels removed.\n", "\n", " \n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def removeVowels(myString):\n", " '''\n", " >>> removeVowels('bookkeeper')\n", " 'bkkpr'\n", " >>> removeVowels('almanac')\n", " 'lmnc'\n", " >>> removeVowels('syzygy')\n", " 'syzygy'\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "removeWordsWithVowels(stringList)\n", "---------------------------------\n", "\n", "Given a list of lower-case strings wordList, return that list with all the words that contain vowels removed.\n", "\n", "append() function to add elements to the end of a list.\">Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def removeWordsWithVowels(stringList):\n", " '''\n", " >>> removeWordsWithVowels(['hymn','myth','myrrh','nymph'])\n", " ['hymn', 'myth', 'myrrh', 'nymph']\n", " >>> removeWordsWithVowels(['who','what','when','where','why'])\n", " ['why']\n", " >>> removeWordsWithVowels(['coy','sly','shy','bashful'])\n", " ['sly', 'shy']\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "spellingBee(correct, guess)\n", "---------------------------\n", "\n", "Given the correct spelling of a word, correct, and the contestant's guessed spelling, guess, return the string \"correct\" if the guess is spelled exactly correctly, \"almost\" if there are at most two mistakes in the spelling, and \"wrong\" if three or more letters are different. You can assume that all guesses are the correct length.\n", "\n", "\n", "Hints" ] }, { "cell_type": "code", "collapsed": false, "input": [ "@test\n", "def spellingBee(correct, guess):\n", " '''\n", " >>> spellingBee('hello', 'hello')\n", " 'correct'\n", " >>> spellingBee('python', 'pithon')\n", " 'almost'\n", " >>> spellingBee('echolocation', 'eckolocashun')\n", " 'wrong'\n", " '''" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*That's all!* If you've made it this far, you're amazing! (Even if you finished up after the workshop.) Hope you get involved with your local Python user group to find out more of the great stuff you can do!" ] } ], "metadata": {} } ] }