Skip to content

Commit 7f63c3d

Browse files
committed
adding assignment 3
1 parent 258f2c6 commit 7f63c3d

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

Assigments/Assignment_3.ipynb

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Third Assignment"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"#### 1) Create a function named **swap ()**, which receives two tuples **a** and **b**, with two elements each. Your code should cause the last elements of the two tuples to be exchanged, and then return the two tuples. "
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": []
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"#### 2) Create the function **dist ()** that takes as an argument two tuples that represent Cartesian coordinates of two points. Your function must return a number that corresponds to the Cartesian distance between these two points."
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": []
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"#### 3) The class **Ball** represents a sphere filled with water (weighing 1000g per cubic meter) with a radius **r** and depending on the surface painting, it can have different weights: blue - weight 1g per square meter: yellow - 2g per square meter or red - 3g per square meter. The class parameter is a tuple **(r, color)**, an integer and a string, respectively. The **weight()** method of the class should return the total weight in kg of the ball (the weight of the water with the external weight of the surface). See example:\n",
43+
"\n",
44+
">```python\n",
45+
">>>> Ball((2, \"red\")).weight()\n",
46+
"> 33.66111808566343\n",
47+
">\n",
48+
">>>> Ball((3, \"blue\")).weight()\n",
49+
"> 113.21043286476177\n",
50+
"\n",
51+
"Hints: \n",
52+
"- Use $\\pi$ = 3.14159\n",
53+
"- Sphere volume: $\\frac43 \\pi r^3$\n",
54+
"- Surface area: $4\\pi r^2$"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {},
61+
"outputs": [],
62+
"source": []
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {},
67+
"source": [
68+
"#### 4) Roman numbers are occasionally used for time stamps or other purposes, but their manual conversion is somewhat laborious. Your task is to implement two functions, ***int_to_Roman() ]*** which converts an integer to Roman (in string) and **Roman_to_int()** which does the reverse. See examples below:\n",
69+
"\n",
70+
">```python\n",
71+
">>>> int_to_Roman(1)\n",
72+
"> I\n",
73+
">>>> int_to_Roman(3000)\n",
74+
"> MMM\n",
75+
">\n",
76+
">>>> Roman_to_int('MMMCMLXXXVI')\n",
77+
"> 3986\n",
78+
">>>> Roman_to_int('C')\n",
79+
"> 100\n",
80+
"\n",
81+
"Note: All test cases will be less than 4000, so you do not have to worry about the characters with bars above them, used in some versions of the Roman numbering system."
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {},
88+
"outputs": [],
89+
"source": []
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": []
97+
},
98+
{
99+
"cell_type": "markdown",
100+
"metadata": {},
101+
"source": [
102+
"#### 5) The **area()** function receives a list **l** of ordered pairs. These ordered pairs represent the vertices of a convex polygon in the Cartesian plane traversed in a single direction. There is a mathematical method that, given the coordinates of the vertices of a polygon, the area can be calculated. You can find more details about the method by clicking [here](https://www.mathopenref.com/coordpolygonarea.html). Your code should make the function return the number that corresponds to the area of the polygon represented by the entry (round to two decimal places). See the following examples:\n",
103+
"\n",
104+
">```python\n",
105+
">>>> area([(0,0),(5,0),(13,8)])\n",
106+
"> 20.00\n",
107+
">\n",
108+
">>>> area([(2,0),(6,0),(10,4),(0,4)])\n",
109+
"> 28.00\n",
110+
"```"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"metadata": {},
117+
"outputs": [],
118+
"source": []
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"## Challenge\n",
125+
"\n",
126+
"#### 6) The function **matches()** receives a list **l** of ordered distinct integers and an integer **n**. Its implementation should cause it to return a list of tuples, each tuple with **n** elements, containing all possible combinations **n** by **n** of the elements in the list **l** (order does not matter). You should only return a list **r** containing the generated tuples. Make sure that tuples are ordered in the list. See the examples below:\n",
127+
"\n",
128+
">```python\n",
129+
">>>> matches([1,2,3,4],2)\n",
130+
"> [(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)]\n",
131+
">\n",
132+
">>>> matches([1,2,3,4],3)\n",
133+
"> [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]\n"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {},
140+
"outputs": [],
141+
"source": []
142+
}
143+
],
144+
"metadata": {
145+
"kernelspec": {
146+
"display_name": "Python 3",
147+
"language": "python",
148+
"name": "python3"
149+
},
150+
"language_info": {
151+
"codemirror_mode": {
152+
"name": "ipython",
153+
"version": 3
154+
},
155+
"file_extension": ".py",
156+
"mimetype": "text/x-python",
157+
"name": "python",
158+
"nbconvert_exporter": "python",
159+
"pygments_lexer": "ipython3",
160+
"version": "3.8.5"
161+
}
162+
},
163+
"nbformat": 4,
164+
"nbformat_minor": 4
165+
}

0 commit comments

Comments
 (0)