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
245 changes: 212 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": 11,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +33,20 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'tuple'>\n"
]
}
],
"source": [
"# Your code here"
"typ = type(tup)\n",
"print(typ)"
]
},
{
Expand All @@ -55,13 +64,36 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"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-13-71e516e24411>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Your code here\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\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\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"o\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mtup\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"n\"\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",
"\n",
"# Your explanation here\n"
"tup.append(\"r\")\n",
"tup.append(\"o\")\n",
"tup.append(\"n\")\n",
"tup.append(\"h\")\n",
"tup.append(\"a\")\n",
"tup.append(\"c\")\n",
"tup.append(\"k\")\n",
"\n",
"\n",
"# Your explanation here\n",
"\n",
"#Tuples are an inmutable kind of object\n"
]
},
{
Expand All @@ -79,13 +111,26 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 19,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(tup)\n",
"\n",
"# Your explanation here\n",
"\n",
"#Yes, we're able to change it as long as we are redifining the variable"
]
},
{
Expand All @@ -103,11 +148,25 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 31,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup1 is: ('I', 'r', 'o', 'n')\n",
"tup2 is: ('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"l=len(tup)\n",
"tup1 = tup[:int(a/2)]\n",
"tup2 = tup[-int(a/2):]\n",
"print(\"tup1 is:\",tup1)\n",
"print(\"tup2 is:\",tup2)\n"
]
},
{
Expand All @@ -121,11 +180,26 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"True\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup3 = tup1+tup2\n",
"print(tup3)\n",
"\n",
"check = tup3 == tup\n",
"print(check)\n"
]
},
{
Expand All @@ -137,11 +211,27 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 38,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"count1 = len(tup1)\n",
"count2 = len(tup2)\n",
"count12 = count1+count2\n",
"count3 = len(tup3)\n",
"\n",
"check12_3 = count12 == count3\n",
"print(check12_3)\n"
]
},
{
Expand All @@ -153,11 +243,23 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 39,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"\n",
"h_ind = tup3.index(\"h\")\n",
"\n",
"print(h_ind)"
]
},
{
Expand All @@ -177,11 +279,32 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 43,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a : True\n",
"b : False\n",
"c : True\n",
"d : False\n",
"e : False\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for i in letters:\n",
" if i in tup3:\n",
" print(i,\":\",True)\n",
" else:\n",
" print(i,\":\",False)\n",
"\n"
]
},
{
Expand All @@ -195,11 +318,37 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 59,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a : 1\n",
"b : 0\n",
"c : 1\n",
"d : 0\n",
"e : 0\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"\n",
"dict_1 = {}\n",
"for i in tup3:\n",
" if i in dict_1:\n",
" dict_1[i] += 1\n",
" else:\n",
" dict_1[i] = 1\n",
"\n",
"for j in letters:\n",
" if j in tup3:\n",
" print(j,\":\",dict_1[j])\n",
" else:\n",
" print(j,\":\",0) \n"
]
},
{
Expand All @@ -211,12 +360,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 67,
"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"
"# Your code here\n",
"\n",
"tupl = (10,20)\n",
"(min1,max1) = tupl\n",
"\n",
"for i in range(min1,max1+1):\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -235,7 +414,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
Loading