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
202 changes: 172 additions & 30 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1,)\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (1,)\n",
"print(mytuple)\n"
]
},
{
Expand All @@ -33,14 +43,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"type(tup)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -55,13 +78,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "unterminated string literal (detected at line 3) (29588915.py, line 3)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Cell \u001b[1;32mIn[15], line 3\u001b[1;36m\u001b[0m\n\u001b[1;33m tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k',)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unterminated string literal (detected at line 3)\n"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k',)\n",
"\n",
"# Your explanation here\n",
"\n",
"No because once a tuple is created, it is inmutable"
]
},
{
Expand All @@ -79,13 +115,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup\n",
"\n",
"# Your explanation here\n",
"\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"#Values inside tuple weren't changed, the tuple itself was changed entirely. It's a different tuple with the same name\n",
"\n",
"\n"
]
},
{
Expand All @@ -103,11 +147,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n')\n",
"('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup\n",
"\n",
"tup1 = tup[0:4]\n",
"tup2 = tup[-4:]\n",
"print(tup1)\n",
"print(tup2)"
]
},
{
Expand All @@ -121,11 +180,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup3 = tup1 + tup2\n",
"tup3\n"
]
},
{
Expand All @@ -137,11 +210,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"targetlen = len(tup3)\n",
"\n",
"count1 = len(tup1)\n",
"count2 = len(tup2)\n",
"count3 = count1 + count2\n",
"count3 == targetlen\n",
"\n"
]
},
{
Expand All @@ -153,11 +245,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"index_h = tup3.index(\"h\")\n",
"index_h\n"
]
},
{
Expand All @@ -177,11 +282,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 62,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n",
"False\n",
"False\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for letter in letters:\n",
" if letter in tup3:\n",
" print(True)\n",
" else:\n",
" print(False)\n"
]
},
{
Expand All @@ -195,11 +320,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 64,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'a': 1, 'b': 0, 'c': 1, 'd': 0, 'e': 0}\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"mydict = {}\n",
"\n",
"for letter in letters:\n",
" count = tup3.count(letter)\n",
" mydict[letter] = count\n",
"\n",
"print(mydict)\n",
" "
]
}
],
Expand All @@ -219,7 +361,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
Loading