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 242dde0

Browse files
Solved Basics of Python Assignment-1
0 parents commit 242dde0

File tree

1 file changed

+294
-0
lines changed

1 file changed

+294
-0
lines changed

‎Assignment-1.ipynb

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Operators are something by which we ca perform operations like adding,multiplying,dividing\n",
8+
"### Values are something that we can store in memory or variable and use it later \n",
9+
"\n",
10+
"- Operators are :- +, *, -, /\n",
11+
"- Values :- 'hello', -87.8\n",
12+
"\n"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"## String :- String is something that is wrapped in single or doublequotes, It is a value\n",
20+
"## Variable :- Variables are used to store data or value in it\n",
21+
"- for ex:- spam = \"Spam\"\n",
22+
"- here spam is a variable that holds string value named \"Spam\"."
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 2,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"spam = 'Spam'"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 3,
37+
"metadata": {},
38+
"outputs": [
39+
{
40+
"data": {
41+
"text/plain": [
42+
"'Spam'"
43+
]
44+
},
45+
"execution_count": 3,
46+
"metadata": {},
47+
"output_type": "execute_result"
48+
}
49+
],
50+
"source": [
51+
"spam"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 4,
57+
"metadata": {},
58+
"outputs": [
59+
{
60+
"data": {
61+
"text/plain": [
62+
"str"
63+
]
64+
},
65+
"execution_count": 4,
66+
"metadata": {},
67+
"output_type": "execute_result"
68+
}
69+
],
70+
"source": [
71+
"type(spam)"
72+
]
73+
},
74+
{
75+
"cell_type": "markdown",
76+
"metadata": {},
77+
"source": [
78+
"## Three Types of DataForms are Int,Float,String"
79+
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"## An expression is a combination of values, variables, operators, and calls to functions. Expressions need to be evaluated."
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 9,
91+
"metadata": {},
92+
"outputs": [
93+
{
94+
"name": "stdout",
95+
"output_type": "stream",
96+
"text": [
97+
"The sum of the two numbers are 5\n"
98+
]
99+
}
100+
],
101+
"source": [
102+
"##Expression example\n",
103+
"b = 2\n",
104+
"a = 3\n",
105+
"## here a+b is an expression\n",
106+
"sum = a+b\n",
107+
"print('The sum of the two numbers is {}'.format(sum))\n"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 11,
113+
"metadata": {},
114+
"outputs": [
115+
{
116+
"name": "stdout",
117+
"output_type": "stream",
118+
"text": [
119+
"20\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"## declaration means we are assigning values to a variable.Here spam=10 is declaration of variable\n",
125+
"spam=10\n",
126+
"## expression means when we are performing operations on it.Here spam *2 is expression\n",
127+
"spam*2\n",
128+
"print(spam*2)"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": 12,
134+
"metadata": {},
135+
"outputs": [
136+
{
137+
"data": {
138+
"text/plain": [
139+
"23"
140+
]
141+
},
142+
"execution_count": 12,
143+
"metadata": {},
144+
"output_type": "execute_result"
145+
}
146+
],
147+
"source": [
148+
"## Here bacon will contain value as 23 because we are adding by +1 to variable bacon which is storing integer value.\n",
149+
"bacon = 22\n",
150+
"bacon + 1\n"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": 14,
156+
"metadata": {},
157+
"outputs": [
158+
{
159+
"data": {
160+
"text/plain": [
161+
"'spamspamspam'"
162+
]
163+
},
164+
"execution_count": 14,
165+
"metadata": {},
166+
"output_type": "execute_result"
167+
}
168+
],
169+
"source": [
170+
"## for both the expressions value would be same because its concatinating 2 strings which holds 3 times spam\n",
171+
"## same for spam*3 it multiplies by 3\n",
172+
"'spam' + 'spamspam'\n",
173+
"'spam' * 3"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"execution_count": 21,
179+
"metadata": {},
180+
"outputs": [
181+
{
182+
"ename": "SyntaxError",
183+
"evalue": "invalid syntax (<ipython-input-21-bbbb2abd74f6>, line 4)",
184+
"output_type": "error",
185+
"traceback": [
186+
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-21-bbbb2abd74f6>\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m 2eggs=100\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
187+
]
188+
}
189+
],
190+
"source": [
191+
"##Why is it that eggs is a true variable name but 100 is not?\n",
192+
"## Ans :- A variable name cannot start with a number.Its defined in the rules of python variable declaration.\n",
193+
"\n",
194+
"2eggs=100\n",
195+
"2eggs"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": 27,
201+
"metadata": {},
202+
"outputs": [
203+
{
204+
"name": "stdout",
205+
"output_type": "stream",
206+
"text": [
207+
"3\n",
208+
"3.0\n",
209+
"3\n",
210+
"<class 'str'>\n"
211+
]
212+
}
213+
],
214+
"source": [
215+
"## we can use int,float,str functions to convert values\n",
216+
"a=3\n",
217+
"print(a)\n",
218+
"k=float(a)\n",
219+
"print(k)\n",
220+
"z=str(a)\n",
221+
"print(z)\n",
222+
"print(type(z))"
223+
]
224+
},
225+
{
226+
"cell_type": "code",
227+
"execution_count": 30,
228+
"metadata": {},
229+
"outputs": [
230+
{
231+
"ename": "TypeError",
232+
"evalue": "can only concatenate str (not \"int\") to str",
233+
"output_type": "error",
234+
"traceback": [
235+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
236+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
237+
"\u001b[1;32m<ipython-input-30-140d7e9d596f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'I have eaten '\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m99\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m' burritos.'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
238+
"\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
239+
]
240+
}
241+
],
242+
"source": [
243+
"f = 'I have eaten ' + 99 + ' burritos.'"
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": 32,
249+
"metadata": {},
250+
"outputs": [
251+
{
252+
"name": "stdout",
253+
"output_type": "stream",
254+
"text": [
255+
"I have eaten 99 burritos.\n"
256+
]
257+
}
258+
],
259+
"source": [
260+
"## In the above case i will convert 99 into string and then perform the following expression.I will do type casting\n",
261+
"f = 'I have eaten ' + str(99) + ' burritos.'\n",
262+
"print(f)"
263+
]
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": null,
268+
"metadata": {},
269+
"outputs": [],
270+
"source": []
271+
}
272+
],
273+
"metadata": {
274+
"kernelspec": {
275+
"display_name": "Python 3",
276+
"language": "python",
277+
"name": "python3"
278+
},
279+
"language_info": {
280+
"codemirror_mode": {
281+
"name": "ipython",
282+
"version": 3
283+
},
284+
"file_extension": ".py",
285+
"mimetype": "text/x-python",
286+
"name": "python",
287+
"nbconvert_exporter": "python",
288+
"pygments_lexer": "ipython3",
289+
"version": "3.8.5"
290+
}
291+
},
292+
"nbformat": 4,
293+
"nbformat_minor": 4
294+
}

0 commit comments

Comments
(0)

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