Queer European MD passionate about IT
Browse Source

Fix 216 solution

Josh Devlin 8 năm trước cách đây
mục cha
commit
9bbe57563e
2 tập tin đã thay đổi với 63 bổ sung16 xóa
  1. 1 0
      .gitignore
  2. 62 16
      Mission216Solutions.ipynb

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 .ipynb_checkpoints
 __pycache__
 temp.py
+*.db

+ 62 - 16
Mission216Solutions.ipynb

@@ -9,11 +9,35 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 1,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "(0, 'id', 'integer', 0, None, 1)\n",
+      "(1, 'category', 'text', 0, None, 0)\n",
+      "(2, 'nominee', 'text', 0, None, 0)\n",
+      "(3, 'movie', 'text', 0, None, 0)\n",
+      "(4, 'character', 'text', 0, None, 0)\n",
+      "(5, 'won', 'text', 0, None, 0)\n",
+      "(6, 'ceremony_id', 'integer', 0, None, 0)\n",
+      "(1, 'Actor -- Leading Role', 'Javier Bardem', 'Biutiful', 'Uxbal', '0', 1)\n",
+      "(2, 'Actor -- Leading Role', 'Jeff Bridges', 'True Grit', 'Rooster Cogburn', '0', 1)\n",
+      "(3, 'Actor -- Leading Role', 'Jesse Eisenberg', 'The Social Network', 'Mark Zuckerberg', '0', 1)\n",
+      "(4, 'Actor -- Leading Role', 'Colin Firth', \"The King's Speech\", 'King George VI', '1', 1)\n",
+      "(5, 'Actor -- Leading Role', 'James Franco', '127 Hours', 'Aron Ralston', '0', 1)\n",
+      "(6, 'Actor -- Supporting Role', 'Christian Bale', 'The Fighter', 'Dicky Eklund', '1', 1)\n",
+      "(7, 'Actor -- Supporting Role', 'John Hawkes', \"Winter's Bone\", 'Teardrop', '0', 1)\n",
+      "(8, 'Actor -- Supporting Role', 'Jeremy Renner', 'The Town', 'James Coughlin', '0', 1)\n",
+      "(9, 'Actor -- Supporting Role', 'Mark Ruffalo', 'The Kids Are All Right', 'Paul', '0', 1)\n",
+      "(10, 'Actor -- Supporting Role', 'Geoffrey Rush', \"The King's Speech\", 'Lionel Logue', '0', 1)\n"
+     ]
+    }
+   ],
    "source": [
     "import sqlite3\n",
     "conn = sqlite3.connect(\"nominations.db\")\n",
@@ -36,11 +60,23 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 2,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "ename": "OperationalError",
+     "evalue": "table ceremonies already exists",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+      "\u001b[0;31mOperationalError\u001b[0m                          Traceback (most recent call last)",
+      "\u001b[0;32m<ipython-input-2-bfea1ef9962a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     12\u001b[0m             ]\n\u001b[1;32m     13\u001b[0m \u001b[0mcreate_ceremonies\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"create table ceremonies (id integer primary key, year integer, host text);\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mconn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcreate_ceremonies\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     15\u001b[0m \u001b[0minsert_query\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"insert into ceremonies (Year, Host) values (?,?);\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     16\u001b[0m \u001b[0mconn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecutemany\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minsert_query\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0myears_hosts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+      "\u001b[0;31mOperationalError\u001b[0m: table ceremonies already exists"
+     ]
+    }
+   ],
    "source": [
     "years_hosts = [(2010, \"Steve Martin\"),\n",
     "               (2009, \"Hugh Jackman\"),\n",
@@ -74,7 +110,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
@@ -92,7 +128,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
@@ -102,7 +138,8 @@
     "nominee text, \n",
     "movie text, \n",
     "character text, \n",
-    "won text, \n",
+    "won text,\n",
+    "ceremony_id integer,\n",
     "foreign key(ceremony_id) references ceremonies(id));\n",
     "'''\n",
     "\n",
@@ -138,12 +175,12 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
-    "drop_nomimations = \"drop table nominations;\"\n",
-    "conn.execute(drop_nominations_two)\n",
+    "drop_nominations = \"drop table nominations;\"\n",
+    "conn.execute(drop_nominations)\n",
     "\n",
     "rename_nominations_two = \"alter table nominations_two rename to nominations;\"\n",
     "conn.execute(rename_nominations_two)"
@@ -160,7 +197,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
@@ -185,7 +222,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
@@ -209,7 +246,7 @@
    "cell_type": "code",
    "execution_count": null,
    "metadata": {
-    "collapsed": true
+    "collapsed": false
    },
    "outputs": [],
    "source": [
@@ -221,6 +258,15 @@
     "\n",
     "print(conn.execute(\"select * from movies_actors limit 5;\").fetchall())"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": true
+   },
+   "outputs": [],
+   "source": []
   }
  ],
  "metadata": {
@@ -239,7 +285,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.5.0"
+   "version": "3.5.1"
   }
  },
  "nbformat": 4,