Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c53fba8

Browse files
Add files via upload
1 parent 3ee8a8c commit c53fba8

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed

‎Assignment-5.ipynb

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"def lcm(n1,n2):\n",
10+
" if n1>n2:\n",
11+
" higher=n1\n",
12+
" else:\n",
13+
" higher=n2\n",
14+
" value = higher\n",
15+
" while True:\n",
16+
" if higher%n1==0 and higher%n2==0:\n",
17+
" print(\"Lcm of \",n1,\"and \",n2,\"is \",higher)\n",
18+
" break\n",
19+
" else:\n",
20+
" higher=higher+value"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 2,
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdout",
30+
"output_type": "stream",
31+
"text": [
32+
"Lcm of 2 and 3 is 6\n"
33+
]
34+
}
35+
],
36+
"source": [
37+
"lcm(2,3)"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 3,
43+
"metadata": {},
44+
"outputs": [
45+
{
46+
"data": {
47+
"text/plain": [
48+
"2"
49+
]
50+
},
51+
"execution_count": 3,
52+
"metadata": {},
53+
"output_type": "execute_result"
54+
}
55+
],
56+
"source": [
57+
"import math\n",
58+
"math.gcd(4,18)"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 4,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"## logic of hcf\n",
68+
"def giveHCF(a,b):\n",
69+
" if b==0:\n",
70+
" return a\n",
71+
" else:\n",
72+
" return giveHCF(b,a%b)\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 8,
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"data": {
82+
"text/plain": [
83+
"12"
84+
]
85+
},
86+
"execution_count": 8,
87+
"metadata": {},
88+
"output_type": "execute_result"
89+
}
90+
],
91+
"source": [
92+
"giveHCF(12,48)"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 10,
98+
"metadata": {},
99+
"outputs": [
100+
{
101+
"name": "stdout",
102+
"output_type": "stream",
103+
"text": [
104+
"The decimal value of 344 is:\n",
105+
"Binary value of number 344 is 0b101011000\n",
106+
"Octal value of number 344 is 0o530\n",
107+
"Hexadecimal value of number 344 is 0x158\n"
108+
]
109+
}
110+
],
111+
"source": [
112+
"dec = 344\n",
113+
"\n",
114+
"print(\"The decimal value of\", dec, \"is:\")\n",
115+
"print(\"Binary value of number\",dec,\"is\",bin(dec))\n",
116+
"print(\"Octal value of number\",dec,\"is\",oct(dec))\n",
117+
"print(\"Hexadecimal value of number\",dec,\"is\",hex(dec))"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 11,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"The ASCII value of 'T' is 84\n"
130+
]
131+
}
132+
],
133+
"source": [
134+
"ch = 'T'\n",
135+
"print(\"The ASCII value of '\" + ch + \"' is\", ord(ch))"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": 18,
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"def calculator():\n",
145+
" print(\"+\")\n",
146+
" print(\"-\")\n",
147+
" print(\"*\")\n",
148+
" print(\"/\")\n",
149+
" operation = input(\"Select an operator:\")\n",
150+
" print(\"Enter two numbers\")\n",
151+
" number_1 = int(input())\n",
152+
" number_2 = int(input())\n",
153+
"\n",
154+
" if operation == '+': # To add two numbers\n",
155+
" print(\"The Addition of number is \",number_1 + number_2)\n",
156+
"\n",
157+
" elif operation == '-': # To subtract two numbers\n",
158+
" print(\"The Substraction of number is \",number_1 - number_2)\n",
159+
"\n",
160+
" elif operation == '*': # To multiply two numbers\n",
161+
" print(\"The Multiplication of number is \",number_1 * number_2)\n",
162+
"\n",
163+
" elif operation == '/': # To divide two numbers\n",
164+
" print(\"The Division of number is \",number_1 / number_2)\n",
165+
"\n",
166+
" else:\n",
167+
" print('Invalid Input')"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 19,
173+
"metadata": {},
174+
"outputs": [
175+
{
176+
"name": "stdout",
177+
"output_type": "stream",
178+
"text": [
179+
"+\n",
180+
"-\n",
181+
"*\n",
182+
"/\n",
183+
"Select an operator:*\n",
184+
"Enter two numbers\n",
185+
"8\n",
186+
"9\n",
187+
"The Multiplication of number is 72\n"
188+
]
189+
}
190+
],
191+
"source": [
192+
"calculator()"
193+
]
194+
}
195+
],
196+
"metadata": {
197+
"kernelspec": {
198+
"display_name": "Python 3",
199+
"language": "python",
200+
"name": "python3"
201+
},
202+
"language_info": {
203+
"codemirror_mode": {
204+
"name": "ipython",
205+
"version": 3
206+
},
207+
"file_extension": ".py",
208+
"mimetype": "text/x-python",
209+
"name": "python",
210+
"nbconvert_exporter": "python",
211+
"pygments_lexer": "ipython3",
212+
"version": "3.8.5"
213+
}
214+
},
215+
"nbformat": 4,
216+
"nbformat_minor": 4
217+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /