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
195 changes: 161 additions & 34 deletions lab-tuple-set-dict/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": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +33,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'tuple'>\n"
]
}
],
"source": [
"# Your code here\n"
"tup = (\"I\",)\n",
"print(type(tup))"
]
},
{
Expand All @@ -55,13 +64,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['I', 'r', 'o', 'n', 'h', 'a', 'c', 'k']\n"
]
}
],
"source": [
"# Your code here\n",
"#I don't know if there's a direct way to append elements, but I think I can use a list\n",
"lst = [\"I\"]\n",
"lst.append(\"r\")\n",
"lst.append(\"o\")\n",
"lst.append(\"n\")\n",
"lst.append(\"h\")\n",
"lst.append(\"a\")\n",
"lst.append(\"c\")\n",
"lst.append(\"k\")\n",
"\n",
"# Your explanation here\n"
"print(lst)"
]
},
{
Expand All @@ -79,13 +104,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"# Your explanation here\n",
"# As I said before, I think I can't do it, so I chose to rewrite tup"
]
},
{
Expand All @@ -103,11 +128,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup1: ('I', 'r', 'o', 'n')\n",
"tup2: ('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"tup1 = tup[:4]\n",
"tup2 = tup[-4:]\n",
"\n",
"print(\"tup1:\", tup1)\n",
"print(\"tup2:\", tup2)"
]
},
{
Expand All @@ -121,11 +160,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup3: ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"tup3 == tup: True\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"tup3 = tup1 + tup2\n",
"\n",
"print(\"tup3:\", tup3)\n",
"print(\"tup3 == tup:\", tup3 == tup)"
]
},
{
Expand All @@ -137,11 +190,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The sum of the counts is equal to the count of tup3\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"tup3 = tup1 + tup2\n",
"\n",
"count_tup1 = len(tup1)\n",
"count_tup2 = len(tup2)\n",
"count_tup3 = len(tup3)\n",
"\n",
"if count_tup1 + count_tup2 == count_tup3:\n",
" print(\"The sum of the counts is equal to the count of tup3\")\n",
"else:\n",
" print(\"The sum of the counts is not equal to the count of tup3\")\n",
"\n"
]
},
{
Expand All @@ -153,11 +226,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The index number of 'h' in tup3 is: 4\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"tup3 = tup1 + tup2\n",
"\n",
"index_h = tup3.index(\"h\")\n",
"\n",
"print(\"The index number of 'h' in tup3 is:\", index_h)"
]
},
{
Expand All @@ -177,11 +264,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n",
"False\n",
"False\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"tup3 = tup1 + tup2\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)"
]
},
{
Expand All @@ -195,17 +303,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The letter a appears 1 time(s) in tup3.\n",
"The letter b appears 0 time(s) in tup3.\n",
"The letter c appears 1 time(s) in tup3.\n",
"The letter d appears 0 time(s) in tup3.\n",
"The letter e appears 0 time(s) in tup3.\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"tup3 = tup1 + tup2\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for letter in letters:\n",
" count = tup3.count(letter)\n",
" print(\"The letter\", letter, \"appears\", count, \"time(s) in tup3.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -219,9 +346,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading