{ "metadata": { "name": "", "signature": "sha256:4d3b23e730c80420389c82b2058b54de7ec3059daf7bf03c4d850c51d583878b" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ " Midterm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This exam can be administered after the students have completed Codecademy and the tours and exercises through [Graphics](../../../Content/Graphics).\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The questions on this midterm are simple programming exercises that you should be able to complete without too much trouble. There are 5 questions and you have 110 minutes, so budget 20 minutes per question, with 10 minutes left over to check your work and push it to github. Make sure you give yourself time to address each question. If you get stuck on one, take it as far as you can go, then move on to the others." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Instructions:** Create a notebook in your main repository directory called `Midterm`. Give it a heading 1 cell title **Midterm**. Answer the questions posed on this page in your notebook. \n", "\n", "**Allowed resources:** \n", "\n", "* You may re-use any code from the tours and exercises that we have done and any code that you have written for this course. \n", "* You may consult any online resource (Google, Wikipedia, StackOverflow, etc.) for guidance or clarification, \n", "* but you *must not copy someone else's code* and use it as your own.\n", "\n", "Save your notebook when you are done and be sure to push it to github before you leave." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Question 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In Robert McCloskey\u2019s book *Make Way for Ducklings*, the names of the ducklings are Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and Quack. This loop outputs these names in order:\n", "\n", " prefixes = 'JKLMNOPQ' \n", " suffix = 'ack'\n", " for letter in prefixes: \n", " print letter + suffix\n", "\n", "The output is:\n", "\n", " Jack \n", " Kack \n", " Lack \n", " Mack \n", " Nack \n", " Oack \n", " Pack \n", " Qack\n", "\n", "Of course, that\u2019s not quite right because \u201cOuack\u201d and \u201cQuack\u201d are misspelled. \n", "\n", "Modify the program to fix this error." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Implement your solution here" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Question 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use `ipythonblocks` to create an 8x8 grid with the first initial of your last name embedded in it in a different color. Use slices and/or loops to set the values rather than setting each block by hand. Here is an example:\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Implement your solution here" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 20 }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Question 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"99 Bottles of Beer\" is a traditional song in the United States and Canada. It is popular to sing on long trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. The song's simple lyrics are as follows:\n", "\n", "```\n", "99 bottles of beer on the wall, 99 bottles of beer. \n", "Take one down, pass it around, 98 bottles of beer on the wall.\n", "```\n", "\n", "The same verse is repeated, each time with one fewer bottle. The song is completed when the singer or singers reach zero.\n", "\n", "Your task here is to write a program capable of generating all the verses of the song." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Implement your solution here" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 21 }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Question 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot a simple graph of a sine function in the range 0 to 3 with a step size of 0.1.\n", "\n", "* Make the line red. \n", "* Add green diamond-shaped markers with size of 7.\n", "* Include legible axis labels.\n", "* Add a legend and a grid to the plot." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Implement your solution here" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 22 }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Question 5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a 100x5 NumPy array called `arr` of random floating point numbers between 10.7 and 36.2. \n", "\n", "* Write the array to a file called `numbers.txt` as 5 columns separated by 2 spaces and formatted with 3 places after the decimal.\n", "* Include a 3-line header that lists the date and time on line 2 (hint: try `!date`).\n", "* Show the first 10 lines of the file using the `!head` command.\n", "* Read the data back in from the file to a new floating point NumPy array called `arr2` and use a slice to print the first ten lines of the array." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Implement your solution here" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 28 }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " All content is under a modified MIT License, and can be freely used and adapted. See the full license text [here](../../../LICENSE)." ] } ], "metadata": {} } ] }