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
186 changes: 153 additions & 33 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": 38,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup=(\"I\",)"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 39,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"type(tup)"
]
},
{
Expand All @@ -55,13 +66,27 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 40,
"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)",
"\u001b[0;32m<ipython-input-40-2356d91806d1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"r\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"o\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"n\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"h\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"a\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"c\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"k\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m# Your explanation here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m# Tuples are unchangeable, so I can not add or remove or reorder elements\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"# Your code here\n",
"tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"# Your explanation here\n",
"\n",
"# Your explanation here\n"
"# Tuples are unchangeable, so I can not add or remove or reorder elements\n"
]
},
{
Expand All @@ -79,13 +104,14 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 45,
"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",
"# I am overwriting the tup element, so when I call \"tup\" in the future I will be working with the last tuple created\n"
]
},
{
Expand All @@ -103,11 +129,25 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 66,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n')\n",
"('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"\n",
"tup1= tup[:4]\n",
"tup2 = tup[-4:]\n",
"\n",
"print (tup1)\n",
"print (tup2)"
]
},
{
Expand All @@ -121,11 +161,33 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 64,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
},
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"\n",
"tup3=(tup1+tup2)\n",
"print(tup3)\n",
"type(tup3)\n",
"len(tup3)"
]
},
{
Expand All @@ -137,11 +199,26 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 67,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n",
"8\n",
"8\n"
]
}
],
"source": [
"# Your code here\n"
"\n",
"print(len(tup1))\n",
"print(len(tup2))\n",
"print(len(tup1)+len(tup2))\n",
"print(len(tup3))"
]
},
{
Expand All @@ -153,11 +230,22 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 69,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"tup3.index(\"h\")"
]
},
{
Expand All @@ -177,11 +265,24 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 71,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a True\n",
"c True\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"for l in letters:\n",
" if l in tup3:\n",
" print(l, \"True\")"
]
},
{
Expand All @@ -195,11 +296,22 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 80,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"for l in letters:\n",
" r+=tup3.count(l)\n",
"print(r)"
]
},
{
Expand All @@ -211,12 +323,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -235,7 +355,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
Loading