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
230 changes: 197 additions & 33 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I',)\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (\"I\",)\n",
"print(tup)"
]
},
{
Expand All @@ -32,11 +42,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"type(tup)"
]
},
{
Expand All @@ -54,13 +76,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39m# Your code here\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m tup\u001b[39m.\u001b[39;49mappend(\u001b[39m\"\u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mn\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mh\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39ma\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mc\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mk\u001b[39m\u001b[39m\"\u001b[39m,)\n\u001b[1;32m 3\u001b[0m \u001b[39m# Your explanation here\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[39m# You can't append because it's not an atribute of touple because it's unnmutable. Although you can concatenate several touples.\u001b[39;00m\n",
"\u001b[0;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\",)\n",
"# Your explanation here\n",
"# You can't append because it's not an atribute of touple because it's unnmutable. Although you can concatenate several touples."
]
},
{
Expand All @@ -80,13 +115,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
},
{
"data": {
"text/plain": [
"\"you can do it because you can redefine what tup includes althoug \\nif you wanted to reassign a value in tup with a new value you'd first had to convert tup into a list\""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\", )\n",
"type(tup)\n",
"print(tup)\n",
"# Your explanation here\n",
"#once you create a touple you can not modify it\n",
"'''you can do it because you can redefine what tup includes althoug \n",
"if you wanted to reassign a value in tup with a new value you'd first had to convert tup into a list'''"
]
},
{
Expand All @@ -104,11 +162,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"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\n",
"tup_1 = tup [0:4]\n",
"tup_2 = tup [4:]\n",
"print(tup_1)\n",
"print(tup_2)\n"
]
},
{
Expand All @@ -122,11 +193,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code code here\n",
"\n",
"tup_3 = tup_1 + tup_2\n",
"\n",
"print(tup_3)"
]
},
{
Expand All @@ -138,11 +221,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n",
"8\n",
"8\n",
"The sum of count of elements in tup 1 and tup 2, and the count of elements in tup 3 it's the same \n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"count_elem = len(tup_1)\n",
"print(count_elem)\n",
"count_elem2 = len(tup_2)\n",
"print(count_elem2)\n",
"sum_count = count_elem + count_elem2\n",
"print (sum_count)\n",
"count_elem3 = len(tup_3)\n",
"print(count_elem3)\n",
"\n",
"if count_elem3 == sum_count:\n",
" print (\"The sum of count of elements in tup 1 and tup 2, and the count of elements in tup 3 it's the same \")\n"
]
},
{
Expand All @@ -154,11 +260,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup_3.index(\"h\")"
]
},
{
Expand All @@ -178,11 +297,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a\n",
"c\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for item in letters:\n",
" if item in tup_3:\n",
" print(item)\n"
]
},
{
Expand All @@ -203,12 +337,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the appearences of the letter a are :1\n",
"b does not appear\n",
"the appearences of the letter c are :1\n",
"d does not appear\n",
"e does not appear\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"\n",
"for item in letters:\n",
" count_appearences = 0\n",
" if item in tup_3:\n",
" count_appearences += 1 \n",
" print(f\"the appearences of the letter {item} are :{count_appearences}\")\n",
"\n",
" else:\n",
" print(f\"{item} does not appear\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -227,7 +391,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.6"
},
"toc": {
"base_numbering": 1,
Expand Down
Loading