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
233 changes: 200 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": 3,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup = ('I',)"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"type(tup)"
]
},
{
Expand All @@ -55,13 +66,32 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'tuple' object has no attribute 'append'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-5-f710692110f1>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"o\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"n\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"h\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"a\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"c\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"k\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"tup.append(\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"#Append method does not work with tuples becasue they are inmutable."
]
},
{
Expand All @@ -79,13 +109,12 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = ('I','r','o','n','h','a','c','k')\n",
"# For re-assigning we create a new taple because tuples are inmutables and they do not work like lists."
]
},
{
Expand All @@ -103,11 +132,24 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 8,
"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",
"tup1 = tup[0:4]\n",
"print(tup1)\n",
"tup2 = tup[-4:]\n",
"print(tup2)"
]
},
{
Expand All @@ -121,11 +163,20 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = tup1 + tup2\n",
"print(tup3)"
]
},
{
Expand All @@ -137,11 +188,33 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 79,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"t1 = len(tup1)\n",
"t2 = len(tup2)\n",
"t3 = len(tup3)"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t1 + t2 == t3"
]
},
{
Expand All @@ -153,11 +226,22 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 81,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"tup3.index('h')"
]
},
{
Expand All @@ -177,11 +261,31 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 82,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]"
]
},
{
"cell_type": "code",
"execution_count": 94,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is in tup3\n",
"c is in tup3\n"
]
}
],
"source": [
"for i in letters:\n",
" if i in tup3:\n",
" print(i ,'is in tup3')"
]
},
{
Expand All @@ -195,11 +299,31 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 100,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a appears:\n",
"1\n",
"b appears:\n",
"0\n",
"c appears:\n",
"1\n",
"d appears:\n",
"0\n",
"e appears:\n",
"0\n"
]
}
],
"source": [
"# Your code here\n"
"for i in letters:\n",
" print(i,'appears:')\n",
" print(tup3.count(i))\n",
" "
]
},
{
Expand All @@ -211,12 +335,55 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 103,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n",
"11\n",
"12\n",
"13\n",
"14\n",
"15\n",
"16\n",
"17\n",
"18\n",
"19\n"
]
}
],
"source": [
"# Your code here\n"
"a, b, c, d, e, f, g, h, i, j = range(10,20)\n",
"\n",
"print(a)\n",
"print(b)\n",
"print(c)\n",
"print(d)\n",
"print(e)\n",
"print(f)\n",
"print(g)\n",
"print(h)\n",
"print(i)\n",
"print(j)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -235,7 +402,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
Loading