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
204 changes: 172 additions & 32 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 96,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"tup = (\"I\", )\n"
]
},
{
Expand All @@ -32,11 +32,19 @@
},
{
"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"
"print (type(tup))\n"
]
},
{
Expand All @@ -54,13 +62,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 97,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"new_list = [\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n",
"\n",
"# Your explanation here\n"
"tup_list = list(tup)\n",
"\n",
"tup_list.extend(new_list)\n",
"\n",
"tup = tuple(tup_list)\n",
"\n",
"print (tup)"
]
},
{
Expand All @@ -80,13 +102,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 105,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"new_list2 = [\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n",
"tup = (\"I\", )\n",
"\n",
"# Your explanation here\n"
"tup_list = list(tup)\n",
"\n",
"tup_list.extend(new_list2[1:])\n",
"\n",
"tup = tuple(tup_list)\n",
"\n",
"print (tup)\n",
"\n"
]
},
{
Expand All @@ -104,11 +142,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 93,
"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)"
]
},
{
Expand All @@ -122,11 +173,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 103,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"tup3 is equal to tup\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = tup1 + tup2\n",
"print (tup3)\n",
"\n",
"if tup3 == tup:\n",
" print (\"tup3 is equal to tup\") \n",
"else:\n",
" print (\"tup3 is not equal to tup\") "
]
},
{
Expand All @@ -138,11 +204,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 108,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n",
"Total count is equal to tup3\n"
]
}
],
"source": [
"# Your code here\n"
"count1 = len(tup1)\n",
"count2 = len(tup2)\n",
"\n",
"total_count = count1 + count2 \n",
"\n",
"\n",
"if total_count == len(tup3): \n",
" print (\"Total count is equal to tup3\")\n",
"else: \n",
" print (\"Total count is not equal to tup3\") \n",
" "
]
},
{
Expand All @@ -154,11 +240,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 109,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"tup3.index(\"h\")"
]
},
{
Expand All @@ -178,11 +275,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 113,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n",
"False\n",
"False\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\")\n",
" else: \n",
" print (\"False\")\n",
" \n",
" \n",
" "
]
},
{
Expand All @@ -203,12 +321,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 118,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"0\n",
"1\n",
"0\n",
"0\n"
]
}
],
"source": [
"# Your code here\n"
"for i in letters:\n",
" print (tup3.count(i))\n",
" \n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -227,7 +367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.11.4"
},
"toc": {
"base_numbering": 1,
Expand Down
Loading