Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 135 additions & 35 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"type(tup) "
]
},
{
Expand All @@ -55,13 +66,27 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-f710692110f1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"r\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"o\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"n\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"h\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"a\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"c\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"k\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"\n",
"tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"#tupples are inmutable so they will not have an append feature\n"
]
},
{
Expand All @@ -79,13 +104,11 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")"
]
},
{
Expand All @@ -103,11 +126,24 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 28,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n')\n",
"('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = tup[0:4]\n",
"tup2 = tup[4:]\n",
"\n",
"print(tup1)\n",
"print(tup2)\n"
]
},
{
Expand All @@ -121,11 +157,21 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 30,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = tup1 + tup2 \n",
"\n",
"print(tup3)\n"
]
},
{
Expand All @@ -137,11 +183,23 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n",
"8\n"
]
}
],
"source": [
"# Your code here\n"
"print(len(tup1))\n",
"print(len(tup2))\n",
"print(len(tup1) + len(tup2))"
]
},
{
Expand All @@ -153,11 +211,19 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 36,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the position of h in tup3 is: 4\n"
]
}
],
"source": [
"# Your code here"
"print(\"the position of h in tup3 is: \", tup3.index(\"h\"))\n"
]
},
{
Expand All @@ -177,11 +243,33 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 45,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the letter a is in tup3 True\n",
"the letter b is in tup3 False\n",
"the letter c is in tup3 True\n",
"the letter d is in tup3 False\n",
"the letter e is in tup3 False\n"
]
}
],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"#for letter in letters: \n",
"# if letter in tup3:\n",
"# print(letter, \"is in tup3\", \"True\")\n",
"# else:\n",
"# print(letter, \"is not in tup3\", \"False\")\n",
"\n",
"\n",
"for letter in letters:\n",
" print(\"the letter\", letter, \"is in tup3 \", letter in tup3) "
]
},
{
Expand All @@ -195,11 +283,25 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 41,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the letters are ['a', 'c']\n"
]
}
],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"count = []\n",
"for letter in letters: \n",
" if letter in tup3:\n",
" count.append(letter)\n",
"\n",
"print(\"the letters are \", count)"
]
},
{
Expand All @@ -214,9 +316,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
]
"source": []
}
],
"metadata": {
Expand All @@ -235,7 +335,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.0"
}
},
"nbformat": 4,
Expand Down
Loading