{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 1: Rock-Paper-Scissors\n", "\n", "Implement a set of games of rock-paper-scissors against the computer. \n", "\n", " * Ask for input from the user (\"rock\", \"paper\", or \"scissors\") and the randomly select one of these for the computer's play.\n", " * Announce who won.\n", " * Keep playing until a player says that they no longer want to play.\n", " * When all games are done, print out how many games were won by the player and by the computer " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 2: Pascal's triangle\n", "\n", "Pascal's triangle is created such that each layer has 1 more element than the previous, with `1`s on the side and in the interior, the numbers are the sum of the two above it, e.g.,:\n", "```\n", " 1\n", " 1 1\n", " 1 2 1\n", " 1 3 3 1\n", " 1 4 6 4 1\n", " 1 5 10 10 5 1\n", "```\n", "\n", "Write a function to return the first `n` rows of Pascal's triangle. The return should be a list of length `n`, with each element itself a list containing the numbers for that row.\n", "\n", " If you want to add complexity, write a function to print out Pascal's triangle with proper formatting, so the numbers in each row are centered between the ones in the row above" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 3: Panagrams\n", "\n", "A _panagram_ is a sentence that includes all 26 letters of the alphabet, e.g., \"_The quick brown fox jumps over the lazy dog_.\"\n", "\n", "Write a function that takes as an argument a sentence and returns `True` or `False`, indicating whether the sentence is a panagram." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 4: Math practice\n", "\n", "We want to make a simple table of trigonometric functions for different angles. Write a code that outputs in columns, the following data:\n", "```\n", "angle (degrees) angle (radians) sin(angle) cos(angle) sin(angle)**2 + cos(angle)**2\n", "```\n", "\n", "For all angles spaced 30 degrees apart in the range 0 to 360 degrees.\n", "\n", "Keep in mind that the trig functions expect the input in radians." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 5: Calendar events\n", "\n", "We want to keep a schedule of events. We will do this by creating a class called `Day`. It is sketched out below. A `Day` holds a list of events and has methods that allow you to add an delete events. Our events will be instances of a class `Event`, which holds the time, location, and description of the event.\n", "\n", "Finally, we can keep track of a list of all the `Day`s for which we have events to make our schedule.\n", "\n", "Fill in these classes and write some code to demonstrate their use:\n", "\n", " * Create a full week of days in your calendar\n", " * Add an event every day at noon called \"lunch\"\n", " * Randomly add some other events to fill out your calendar\n", " * Write some code that tells you the start time of your first meeting and the end time of your last meeting (this is the length of your work day)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "class Day:\n", " \"\"\"a single day keeping track of the events scheduled\"\"\"\n", " def __init__(month, day, year):\n", " # store the month, day, and year as data in the class\n", " \n", " # keep track of the events\n", " self.events = []\n", " \n", " def add_event(name, time=None, location=None):\n", " pass\n", " \n", " def delete_event(name):\n", " pass\n", " \n", " \n", "class Event:\n", " \"\"\"a single event in our calendar\"\"\"\n", " def __init__(name, time=9, location=None, duration=1):\n", " self.name = name\n", " self.time = time\n", " self.location = location\n", " self.duration = duration" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }