Commit 5ae6c4c2 by Tommy Marrinan

### update function sort

parent 739b78c6
 ... ... @@ -29,7 +29,7 @@ "\n", "print(\"orginal myarray %s\" % myarray)\n", "\n", "# sort the list: each iteration moves the smallest remaining number\n", "# sort the list: each iteration moves the smallest remaining number to position 'i'\n", "for i in range(len(myarray)):\n", " for j in range(i+1, len(myarray)):\n", " if myarray[j] < myarray[i]:\n", ... ... @@ -48,30 +48,36 @@ "source": [ "# Now sort using functions!\n", "\n", "\n", "# function to fill and array with 'num_items' elements of random numbers between 1 and 100\n", "#def populate_random(array, num_items):\n", " # code populating a list here\n", "\n", "\n", "# function to sort a list from lowest to highest\n", "#def sort(array):\n", " # code sort algorithm here \n", " \n", "\n", "\n", "arr1 = []\n", "#populate_random(arr1, 10)\n", "print(\"\\norginal arr1 %s\" % arr1)\n", "print(\"\")\n", "print(\"orginal arr1 %s\" % arr1)\n", "#sort(arr1)\n", "print(\"sorted arr1 %s\" % arr1)\n", "\n", "\n", "arr2 = []\n", "#populate_random(arr2, 6)\n", "print(\"\\norginal arr2 %s\" % arr2)\n", "print(\"\")\n", "print(\"orginal arr2 %s\" % arr2)\n", "#sort(arr2)\n", "print(\"sorted arr2 %s\" % arr2)\n", "\n", "arr3 = []\n", "#populate_random(arr3, 14)\n", "print(\"\\norginal arr3 %s\" % arr3)\n", "print(\"\")\n", "print(\"orginal arr3 %s\" % arr3)\n", "#sort(arr3)\n", "print(\"sorted arr3 %s\" % arr3)" ] ... ... @@ -92,7 +98,9 @@ { "cell_type": "code", "execution_count": null, "metadata": {}, "metadata": { "collapsed": true }, "outputs": [], "source": [ "string1 = \"the morse code\"\n", ... ... @@ -104,18 +112,20 @@ "string2_chars = list(string2)\n", "string3_chars = list(string3)\n", "\n", "\n", "# compare the characters to see if they are the same\n", "# code here!\n", "\n", "if string1_chars == string2_chars:\n", " print(\"'%s' has same chars as '%s'\" % (string1, string2))\n", "else:\n", " print(\"'%s' has different chars from '%s'\" % (string1, string2))\n", "\n", "if string1_chars == string3_chars:\n", " print(\"'%s' has same chars as '%s'\" % (string1, string3))\n", "else:\n", " print(\"'%s' has different chars from '%s'\" % (string1, string3))" "# if characters in string1 are the same as characters in string2\n", "# print `string1` has same characters as `string2`\n", "# else\n", "# print `string1` has different characters from `string2`\n", "\n", "# if characters in string1 are the same as characters in string3\n", "# print `string1` has same characters as `string3`\n", "# else\n", "# print `string1` has different characters from `string3`" ] } ], ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!