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
213 changes: 178 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": 3,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"type(tup)"
]
},
{
Expand All @@ -55,13 +66,11 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"list_1 = list(tup)"
]
},
{
Expand All @@ -79,13 +88,29 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(tup)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"Yes, you can reassign the new elements to the tuple. You change the information on the placeholder tup."
]
},
{
Expand All @@ -103,11 +128,49 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n')\n",
"('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"tup1 = (tup[:4])\n",
"tup2 = (tup[-4:])\n",
"\n",
"print(tup1)\n",
"print(tup2)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"#list_2 = list(tup)\n",
"\n",
"#tup1 = []\n",
"#tup2 = []\n",
"\n",
"#for i in list_2[:4]:\n",
"# tup1.append(i)\n",
"#for i in list_2[-4:]:\n",
"# tup2.append(i)\n",
"\n",
"#tup1 = tuple(tup1)\n",
"#tup2 = tuple(tup2)\n",
"\n",
"#print(tup1)\n",
"#print(tup2)"
]
},
{
Expand All @@ -121,11 +184,20 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 39,
"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",
"print(tup3)"
]
},
{
Expand All @@ -137,11 +209,22 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"len(tup1) + len(tup2) == len(tup3)"
]
},
{
Expand All @@ -153,11 +236,22 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 45,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"tup3.index(\"h\")"
]
},
{
Expand All @@ -177,11 +271,31 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True a is in the tuple.\n",
"False b is not in the tuple.\n",
"True c is in the tuple.\n",
"False d is not in the tuple.\n",
"False e is not in the tuple.\n"
]
}
],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for i in letters:\n",
" if i in tup3:\n",
" print(\"True \", i, \" is in the tuple.\")\n",
" else:\n",
" print(\"False\", i, \" is not in the tuple.\")\n",
" \n",
" \n"
]
},
{
Expand All @@ -195,11 +309,25 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a 1\n",
"b 1\n",
"c 1\n",
"d 1\n",
"e 1\n"
]
}
],
"source": [
"# Your code here\n"
"for i in letters:\n",
" if i in letters:\n",
" print(i, letters.count(i))"
]
},
{
Expand All @@ -211,12 +339,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)\n"
]
}
],
"source": [
"# Your code here\n"
"print(tuple(range(10,21)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -235,7 +378,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
Loading