up-and-running-solutions.ipynb 3.85 KB
Newer Older
George Mount's avatar
George Mount committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DRILLS\n",
    "\n",
    "1. Assign the sum of -10 and 2 to `a`.\n",
    "2. Assign the absolute value of `a` to `b`.\n",
    "3. Assign `b` minus 1 as `d`.\n",
    "4. Print the result of `d`. What is the value? What type is this variable?\n"
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
17
   "execution_count": null,
George Mount's avatar
George Mount committed
18 19 20
   "metadata": {
    "tags": []
   },
George Mount's avatar
George Mount committed
21
   "outputs": [],
George Mount's avatar
George Mount committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   "source": [
    "a = -10 + 2\n",
    "b = abs(a)\n",
    "d = b - 1\n",
    "\n",
    "print(d)\n",
    "print(type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DRILL\n",
    "\n",
    "1. Create a list containing the values `North`, `East`, `South` and `West`.  \n",
    "2. What is the result of the below?\n",
    "\n",
    "```\n",
    "len(['Monday','Tuesday','Wednesday','Thursday','Friday',['Saturday','Sunday']])\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
47
   "execution_count": null,
George Mount's avatar
George Mount committed
48 49 50
   "metadata": {
    "tags": []
   },
George Mount's avatar
George Mount committed
51
   "outputs": [],
George Mount's avatar
George Mount committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   "source": [
    "directions = ['North','East','South','West']\n",
    "print(directions)\n",
    "\n",
    "print(len(['Monday','Tuesday','Wednesday','Thursday','Friday',['Saturday','Sunday']]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DRILL\n",
    "\n",
    "1. What do you expect to be the result of the following? Run the code and see how you did.\n",
    "\n",
    "```\n",
    "my_week = (['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])\n",
    "my_week.sort()\n",
    "print(my_week)\n",
    "```\n",
    "\n",
    "2. Pass the `clear()` method to `my_week` from above. Re-print `my_week`. What happens?"
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
78
   "execution_count": null,
George Mount's avatar
George Mount committed
79 80 81
   "metadata": {
    "tags": []
   },
George Mount's avatar
George Mount committed
82
   "outputs": [],
George Mount's avatar
George Mount committed
83 84 85
   "source": [
    "my_week = (['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'])\n",
    "my_week.sort()\n",
George Mount's avatar
George Mount committed
86 87
    "\n",
    "my_week"
George Mount's avatar
George Mount committed
88 89 90 91
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
92
   "execution_count": null,
George Mount's avatar
George Mount committed
93 94 95
   "metadata": {
    "tags": []
   },
George Mount's avatar
George Mount committed
96
   "outputs": [],
George Mount's avatar
George Mount committed
97 98
   "source": [
    "my_week.clear()\n",
George Mount's avatar
George Mount committed
99
    "my_week"
George Mount's avatar
George Mount committed
100 101 102 103 104 105 106 107 108 109 110 111 112
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Drill\n",
    "\n",
    "Practice some more slicing below:"
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
113
   "execution_count": null,
George Mount's avatar
George Mount committed
114 115 116
   "metadata": {
    "tags": []
   },
George Mount's avatar
George Mount committed
117
   "outputs": [],
George Mount's avatar
George Mount committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
   "source": [
    "my_list = [7,12,5,10,9]\n",
    "\n",
    "# Get the first through third elements\n",
    "print(my_list[0:3])\n",
    "\n",
    "# Get the third-last to second-last elements\n",
    "print(my_list[-3:-1])\n",
    "\n",
    "# Get the second through last elements\n",
    "print(my_list[1:5])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Drill\n",
    "\n",
    "The `factorial()` function from `math` will take the factorial of a number `X`.\n",
    "\n",
    "Find the factorial of 10 using this function."
   ]
  },
  {
   "cell_type": "code",
George Mount's avatar
George Mount committed
144
   "execution_count": null,
George Mount's avatar
George Mount committed
145
   "metadata": {},
George Mount's avatar
George Mount committed
146
   "outputs": [],
George Mount's avatar
George Mount committed
147 148 149 150 151 152 153 154 155 156 157 158
   "source": [
    "import math\n",
    "\n",
    "math.factorial(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Drill \n",
    "\n",
George Mount's avatar
George Mount committed
159
    "What code is used to install `seaborn`?"
George Mount's avatar
George Mount committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install seaborn"
   ]
  }
 ],
 "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",
George Mount's avatar
George Mount committed
188
   "version": "3.7.4"
George Mount's avatar
George Mount committed
189 190 191 192 193
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}