From 162c040bfa278e9583ff7de145b30f13d2c6adfb Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 1 Aug 2017 10:57:08 +0000 Subject: [PATCH 1/3] I think this is right --- TinaTestPython.ipynb | 96 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 15 deletions(-) diff --git a/TinaTestPython.ipynb b/TinaTestPython.ipynb index a9d76ca..a7c6c82 100644 --- a/TinaTestPython.ipynb +++ b/TinaTestPython.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -36,7 +36,7 @@ "['1', '2', '3', '4', '5', '6', '7', '8', '9']" ] }, - "execution_count": 7, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -49,30 +49,96 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'3' == l[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(False, -1)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linearSearch('3',l)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ - "assert linearSearch(\"3\", l) == (False, -1)" + "def linearSearch(x, l):\n", + " \n", + " for i in range(len(l)):\n", + " if x == l[i]:\n", + " return True, i\n", + " # Fixed indentation\n", + " return False, -1\n", + " " ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "metadata": {}, "outputs": [ { - "ename": "AssertionError", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mlinearSearch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"2\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m: " - ] + "data": { + "text/plain": [ + "(True, 2)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" } ], + "source": [ + "linearSearch('3',l)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "assert linearSearch(3, l) == (False, -1)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], "source": [ "assert linearSearch(\"2\", l) == (True, 1)" ] From af26ae552f9babdc87cc3c36ed6f68f7537424bf Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 1 Aug 2017 11:00:47 +0000 Subject: [PATCH 2/3] minor edit --- TinaTestPython.ipynb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TinaTestPython.ipynb b/TinaTestPython.ipynb index a7c6c82..e8b02b9 100644 --- a/TinaTestPython.ipynb +++ b/TinaTestPython.ipynb @@ -105,6 +105,26 @@ " " ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(False, -1)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linearSearch('A',l)" + ] + }, { "cell_type": "code", "execution_count": 9, From 051a2324226304fd137272bce20eb7673ffa06f2 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 24 Aug 2017 11:29:19 +0000 Subject: [PATCH 3/3] Explain that it does not work --- .../TinaTestPython-checkpoint.ipynb | 199 ++++++++++++++++++ TinaTestPython.ipynb | 15 +- 2 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 .ipynb_checkpoints/TinaTestPython-checkpoint.ipynb diff --git a/.ipynb_checkpoints/TinaTestPython-checkpoint.ipynb b/.ipynb_checkpoints/TinaTestPython-checkpoint.ipynb new file mode 100644 index 0000000..ca9c034 --- /dev/null +++ b/.ipynb_checkpoints/TinaTestPython-checkpoint.ipynb @@ -0,0 +1,199 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# What is wrong with this linear search?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It doesn't work m8s" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def linearSearch(x, l):\n", + " \n", + " for i in range(len(l)):\n", + " if x == l[i]:\n", + " return True, i\n", + " \n", + " return False, -1\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['1', '2', '3', '4', '5', '6', '7', '8', '9']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s=\"123456789\"\n", + "l = list(s)\n", + "l" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'3' == l[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(False, -1)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linearSearch('3',l)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def linearSearch(x, l):\n", + " \n", + " for i in range(len(l)):\n", + " if x == l[i]:\n", + " return True, i\n", + " # Fixed indentation\n", + " return False, -1\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(False, -1)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linearSearch('A',l)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(True, 2)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "linearSearch('3',l)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "assert linearSearch(3, l) == (False, -1)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "assert linearSearch(\"2\", l) == (True, 1)" + ] + } + ], + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/TinaTestPython.ipynb b/TinaTestPython.ipynb index e8b02b9..ca9c034 100644 --- a/TinaTestPython.ipynb +++ b/TinaTestPython.ipynb @@ -7,6 +7,13 @@ "# What is wrong with this linear search?" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It doesn't work m8s" + ] + }, { "cell_type": "code", "execution_count": 2, @@ -148,7 +155,9 @@ { "cell_type": "code", "execution_count": 11, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "assert linearSearch(3, l) == (False, -1)" @@ -157,7 +166,9 @@ { "cell_type": "code", "execution_count": 12, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "assert linearSearch(\"2\", l) == (True, 1)"