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
134 changes: 108 additions & 26 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"# Your code here\n",
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +34,20 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'tuple'>\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"print(type(tup))"
]
},
{
Expand All @@ -55,13 +65,32 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-f33a8a416874>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Your code here\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mtup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"o\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"n\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"h\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"a\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"c\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"k\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Your explanation here:\n",
"Tuples are unchangeable, so we cannot add any elements to the tuple."
]
},
{
Expand All @@ -79,13 +108,21 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(\"Tup is: \", tup)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Your explanation here\n",
"We cannot add any elements to a tuple, but we are able to re-assign the tuples."
]
},
{
Expand All @@ -103,11 +140,15 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"tup1 = tup[0:4]\n",
"tup2 = tup[-4:]"
]
},
{
Expand All @@ -121,11 +162,20 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"tup3 = tup1 + tup2\n",
"print(tup3)\n",
"\n",
"if tup3 == tup:\n",
" print(\"True. Tup3 equals tup\")\n",
"else:\n",
" print(\"Not the same tup3 than tup\")"
]
},
{
Expand All @@ -137,11 +187,19 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"print(\"Number of elements in tup1 is \", len(set(tup1)))\n",
"print(\"Number of elements in tup2 is \", len(set(tup2)))\n",
"print(\"Number of elements in tup3 is \", len(set(tup3)))\n",
"\n",
"if len(set(tup3)) == sum([len(set(tup1)),len(set(tup2))]):\n",
" print(\"True. Elements in tup1+tup2 equals elements in tup3\")\n",
"else:\n",
" print(\"False\")"
]
},
{
Expand All @@ -153,11 +211,13 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"# Your code here\n",
"print(tup3)\n",
"tup3.index(\"h\")"
]
},
{
Expand All @@ -177,11 +237,19 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"print(letters)\n",
"\n",
"for i in letters:\n",
" if i in tup3:\n",
" print(\"True\")\n",
" else:\n",
" print(\"False\")"
]
},
{
Expand All @@ -195,11 +263,14 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"for i in letters:\n",
" print(tup3.count(i))"
]
},
{
Expand All @@ -215,7 +286,18 @@
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"a, b, c, d, e, f, g, h, i, j = range(10, 20)\n",
"print(a)\n",
"print(b)\n",
"print(c)\n",
"print(d)\n",
"print(e)\n",
"print(f)\n",
"print(g)\n",
"print(h)\n",
"print(i)\n",
"print(j)"
]
}
],
Expand All @@ -235,7 +317,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
Loading