Skip to content

Commit bf674af

Browse files
authored
Python Program Assignment
1 parent ae668ed commit bf674af

8 files changed

+2291
-0
lines changed

Assignment-1.ipynb

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "24b000e1",
6+
"metadata": {},
7+
"source": [
8+
"# 1. Write a Python program to print \"Hello Python\"?"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "f25ce0d5",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"Hello World\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"print(\"Hello World\")"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"id": "eb0d93be",
32+
"metadata": {},
33+
"source": [
34+
"# 2. Write a Python program to do arithmetical operations addition and division.?"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 2,
40+
"id": "9383cb8f",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"def arithmaticOperation(a,b):\n",
45+
" \"\"\"Here the function takes two arguments as input values and performs and addition and division \"\"\"\n",
46+
" addition=a+b\n",
47+
" division=a/b\n",
48+
" print(\"Addition value of {0} and {1} is {2}\".format(a,b,addition))\n",
49+
" print(\"Division value of {0} and {1} is {2}\".format(a,b,division))"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 3,
55+
"id": "c1d43601",
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
"Addition value of 100 and 200 is 300\n",
63+
"Division value of 100 and 200 is 0.5\n"
64+
]
65+
}
66+
],
67+
"source": [
68+
"arithmaticOperation(100,200)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"id": "8497ae82",
74+
"metadata": {},
75+
"source": [
76+
"# 3. Write a Python program to find the area of a triangle?"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 4,
82+
"id": "40b70573",
83+
"metadata": {},
84+
"outputs": [
85+
{
86+
"name": "stdout",
87+
"output_type": "stream",
88+
"text": [
89+
"Enter the value of base:10\n",
90+
"Enter the value of height:5\n",
91+
"Area of the triangle is: 25.0\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"def areaOfTriangle(b,h):\n",
97+
" area= 0.5*b*h\n",
98+
" return area\n",
99+
"base=int(input(\"Enter the value of base:\"))\n",
100+
"height=int(input(\"Enter the value of height:\"))\n",
101+
"a=areaOfTriangle(base,height)\n",
102+
"print(\"Area of the triangle is:\",a)"
103+
]
104+
},
105+
{
106+
"cell_type": "markdown",
107+
"id": "599a895b",
108+
"metadata": {},
109+
"source": [
110+
"# 4. Write a Python program to swap two variables?"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": 5,
116+
"id": "d3044025",
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"def swap(a,b):\n",
121+
" \"\"\"Function takes two argument values and swaps their values\"\"\"\n",
122+
" temp=a\n",
123+
" a=b\n",
124+
" b=temp\n",
125+
" print(\"The value of a and b after swapping\",a,b)"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": 6,
131+
"id": "1a3ae216",
132+
"metadata": {},
133+
"outputs": [
134+
{
135+
"name": "stdout",
136+
"output_type": "stream",
137+
"text": [
138+
"The value of a and b after swapping 10 20\n"
139+
]
140+
}
141+
],
142+
"source": [
143+
"swap(20,10)"
144+
]
145+
},
146+
{
147+
"cell_type": "markdown",
148+
"id": "76da2dca",
149+
"metadata": {},
150+
"source": [
151+
"# 5.Write a Python program to generate a random number"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": 7,
157+
"id": "c0dcef88",
158+
"metadata": {},
159+
"outputs": [
160+
{
161+
"name": "stdout",
162+
"output_type": "stream",
163+
"text": [
164+
"3\n"
165+
]
166+
}
167+
],
168+
"source": [
169+
"import random\n",
170+
"list1=[1,2,3,4,5]\n",
171+
"a=random.choice(list1)\n",
172+
"print(a)"
173+
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": 8,
178+
"id": "f5a2fbc9",
179+
"metadata": {},
180+
"outputs": [
181+
{
182+
"name": "stdout",
183+
"output_type": "stream",
184+
"text": [
185+
"0.8942216444756305\n"
186+
]
187+
}
188+
],
189+
"source": [
190+
"print(random.random())"
191+
]
192+
}
193+
],
194+
"metadata": {
195+
"kernelspec": {
196+
"display_name": "Python 3 (ipykernel)",
197+
"language": "python",
198+
"name": "python3"
199+
},
200+
"language_info": {
201+
"codemirror_mode": {
202+
"name": "ipython",
203+
"version": 3
204+
},
205+
"file_extension": ".py",
206+
"mimetype": "text/x-python",
207+
"name": "python",
208+
"nbconvert_exporter": "python",
209+
"pygments_lexer": "ipython3",
210+
"version": "3.9.12"
211+
}
212+
},
213+
"nbformat": 4,
214+
"nbformat_minor": 5
215+
}

0 commit comments

Comments
 (0)