Skip to content

Commit 105bae0

Browse files
authored
Add files via upload
1 parent 492d217 commit 105bae0

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed

A-4.ipynb

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## 1.1. Write a Python Program(with class concepts) to find the area of the triangle using the below formula.\n",
8+
"\n",
9+
"area = (s*(s-a)*(s-b)*(s-c)) ** 0.5"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"l1 :2\n",
22+
"l2 :3\n",
23+
"l3 :4\n",
24+
"area : 2.9047375096555625\n"
25+
]
26+
}
27+
],
28+
"source": [
29+
"class sides_of_triangle():\n",
30+
" def __init__(self, l1, l2, l3):\n",
31+
" self.l1 = float(l1)\n",
32+
" self.l2 = float(l2)\n",
33+
" self.l3 = float(l3)\n",
34+
"l1 = int(input('l1 :'))\n",
35+
"l2 = int(input('l2 :'))\n",
36+
"l3 = int(input('l3 :'))\n",
37+
"\n",
38+
"class area_of_triangle(sides_of_triangle):\n",
39+
" def __init__(self,l1,l2,l3):\n",
40+
" super().__init__(l1,l2,l3)\n",
41+
" \n",
42+
" def get_area(self):\n",
43+
" s = (l1 + l2 + l3) / 2\n",
44+
" return (s*(s-l1)*(s-l2)*(s-l3)) ** 0.5\n",
45+
" \n",
46+
"\n",
47+
"t = area_of_triangle(l1,l2,l3)\n",
48+
"print(\"area : {}\".format(t.get_area()))\n",
49+
" "
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"## 1.2 Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n."
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 7,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"data": {
66+
"text/plain": [
67+
"['paridhi']"
68+
]
69+
},
70+
"execution_count": 7,
71+
"metadata": {},
72+
"output_type": "execute_result"
73+
}
74+
],
75+
"source": [
76+
"def filter_long_words(list1, n):\n",
77+
" list2 =[]\n",
78+
" for word in list1:\n",
79+
" if len(word) > n:\n",
80+
" list2.append(word)\n",
81+
" return list2\n",
82+
"\n",
83+
"list1 = ['paridhi', 'modi', 'table']\n",
84+
"filter_long_words(list1, 5)"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"metadata": {},
90+
"source": [
91+
"## 2.1 Write a Python program using function concept that maps list of words into a list of integers representing the lengths of the corresponding words."
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 2,
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"def len_of_words(l1):\n",
101+
" l2 =[]\n",
102+
" for word in l1:\n",
103+
" x = len(word) \n",
104+
" l2.append(x)\n",
105+
" return l2\n",
106+
" "
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 5,
112+
"metadata": {},
113+
"outputs": [
114+
{
115+
"data": {
116+
"text/plain": [
117+
"[3, 4, 5]"
118+
]
119+
},
120+
"execution_count": 5,
121+
"metadata": {},
122+
"output_type": "execute_result"
123+
}
124+
],
125+
"source": [
126+
"l1 = ['gfd', 'chne', 'atchj']\n",
127+
"len_of_words(l1)"
128+
]
129+
},
130+
{
131+
"cell_type": "markdown",
132+
"metadata": {},
133+
"source": [
134+
"## 2.2 Function which takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise."
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 6,
140+
"metadata": {},
141+
"outputs": [],
142+
"source": [
143+
"l1 = ['a', 'e', 'i', 'o', 'u']\n",
144+
"def vovels(x):\n",
145+
" if x in l1:\n",
146+
" return True\n",
147+
" else:\n",
148+
" retu\n"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": 9,
154+
"metadata": {},
155+
"outputs": [],
156+
"source": [
157+
"vovels('d')"
158+
]
159+
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": null,
163+
"metadata": {},
164+
"outputs": [],
165+
"source": []
166+
}
167+
],
168+
"metadata": {
169+
"kernelspec": {
170+
"display_name": "Python 3",
171+
"language": "python",
172+
"name": "python3"
173+
},
174+
"language_info": {
175+
"codemirror_mode": {
176+
"name": "ipython",
177+
"version": 3
178+
},
179+
"file_extension": ".py",
180+
"mimetype": "text/x-python",
181+
"name": "python",
182+
"nbconvert_exporter": "python",
183+
"pygments_lexer": "ipython3",
184+
"version": "3.8.3"
185+
}
186+
},
187+
"nbformat": 4,
188+
"nbformat_minor": 4
189+
}

0 commit comments

Comments
 (0)