Skip to content
Open

Reka #79

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
176 changes: 145 additions & 31 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": 2,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup = ('I',)"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"type(tup)"
]
},
{
Expand All @@ -55,13 +66,28 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"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-4-e86eeab0ad01>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mletters\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mletters\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\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 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\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[0;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'"
]
}
],
"source": [
"# Your code here\n",
"letters =[\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n",
"\n",
"# Your explanation here\n"
"for i in letters:\n",
" tup.append(letters[i])\n",
"\n",
"# I'm not able to do it because tuples are unchangeable. Meaning once you created you are not able to modify (eg. adding new elements, change/modify) values)\n"
]
},
{
Expand All @@ -79,13 +105,13 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"# Your explanation here\n"
"# Yes, I'm able to do it because now I re-defined the values of the tuple not modify it\n"
]
},
{
Expand All @@ -103,11 +129,23 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"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[:4]\n",
"tup2 = tup[-4:]\n",
"print(tup1)\n",
"print(tup2)\n"
]
},
{
Expand All @@ -121,11 +159,24 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = tup1 + tup2\n",
"\n",
"print(tup3)\n",
"print(tup)\n",
"\n"
]
},
{
Expand All @@ -137,11 +188,26 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8\n",
"8\n"
]
}
],
"source": [
"# Your code here\n"
"num_tup1 = len(tup1)\n",
"num_tup2 = len(tup2)\n",
"num_tup3 = len(tup3)\n",
"num_sum = num_tup1 + num_tup2\n",
"\n",
"print(num_tup3)\n",
"print(num_sum)\n"
]
},
{
Expand All @@ -153,11 +219,22 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here"
"tup3.index('h')"
]
},
{
Expand All @@ -177,11 +254,28 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 50,
"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",
"for i in range(len(letters)):\n",
" if letters[i] in tup3:\n",
" print('True')\n",
" else:\n",
" print('False')\n"
]
},
{
Expand All @@ -195,11 +289,31 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 62,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a num of occ.: 1\n",
"b num of occ.: 0\n",
"c num of occ.: 1\n",
"d num of occ.: 0\n",
"e num of occ.: 0\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"for i in range(len(letters)):\n",
" if letters[i] in tup3:\n",
" print(letters[i], \"num of occ.: \" ,tup3.count(letters[i]))\n",
" else:\n",
" print(letters[i], \"num of occ.: 0\")\n",
"\n",
"\n"
]
},
{
Expand Down Expand Up @@ -235,7 +349,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down
Loading