Skip to content

Commit 6f480bb

Browse files
authored
Add files via upload
1 parent 997524f commit 6f480bb

26 files changed

+9629
-0
lines changed
Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "2e9253cb",
6+
"metadata": {},
7+
"source": [
8+
"# Assignment 3"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "84c2138b",
14+
"metadata": {},
15+
"source": [
16+
"## 1. Why are functions advantageous to have in your programs?"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"id": "c72a42c2",
22+
"metadata": {},
23+
"source": [
24+
"Functions reduce the need for duplicate code. This makes programs shorter, easier to read, and easier to update."
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"id": "68dc26e3",
30+
"metadata": {},
31+
"source": [
32+
"## 2. When does the code in a function run: when it's specified or when it's called?\n"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "fcf8b478",
38+
"metadata": {},
39+
"source": [
40+
"The code in a function executes when the function is called, not when the function is defined."
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"id": "2dd34b68",
46+
"metadata": {},
47+
"source": [
48+
"## 3. What statement creates a function?\n"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"id": "6e59cec8",
54+
"metadata": {},
55+
"source": [
56+
"The def statement defines (that is, creates) a function."
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"id": "51b401b6",
62+
"metadata": {},
63+
"source": [
64+
"## 4. What is the difference between a function and a function call?"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"id": "b7150aff",
70+
"metadata": {},
71+
"source": [
72+
"A function call means invoking or calling that function. Unless a function is called there is no use of that function. So the difference between the function and function call is, A function is procedure to achieve a particular result while function call is using this function to achive that task."
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"id": "d3248d8f",
78+
"metadata": {},
79+
"source": [
80+
"## 5. How many global scopes are there in a Python program? How many local scopes?"
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"id": "2695d491",
86+
"metadata": {},
87+
"source": [
88+
"There is one global scope, and a local scope is created whenever a function is called."
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "cda8277e",
94+
"metadata": {},
95+
"source": [
96+
"## 6. What happens to variables in a local scope when the function call returns?"
97+
]
98+
},
99+
{
100+
"cell_type": "markdown",
101+
"id": "cf948974",
102+
"metadata": {},
103+
"source": [
104+
"variable in a local space is confined to that space of function can only be used in that function and therefore retains its value untill next time function is called."
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"id": "d55f7e5e",
110+
"metadata": {},
111+
"source": [
112+
"## 7. What is the concept of a return value? Is it possible to have a return value in an expression?\n"
113+
]
114+
},
115+
{
116+
"cell_type": "markdown",
117+
"id": "09b2d7f6",
118+
"metadata": {},
119+
"source": [
120+
"A return value is the value that a function call evaluates to. Like any value, a return value can be used as part of an expression."
121+
]
122+
},
123+
{
124+
"cell_type": "markdown",
125+
"id": "afaa5330",
126+
"metadata": {},
127+
"source": [
128+
"## 8. If a function does not have a return statement, what is the return value of a call to that function?"
129+
]
130+
},
131+
{
132+
"cell_type": "markdown",
133+
"id": "c3f75d84",
134+
"metadata": {},
135+
"source": [
136+
"it doesnt return any particular value"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"id": "265a3010",
142+
"metadata": {},
143+
"source": [
144+
"## 9. How do you make a function variable refer to the global variable?\n"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"id": "7c59515f",
150+
"metadata": {},
151+
"source": [
152+
"Global variable is not connected to any particular function which means it is free to be called in any function and also be reused. Therefore to refer a function variable to global variable we use global keyword to declare which variable are global"
153+
]
154+
},
155+
{
156+
"cell_type": "markdown",
157+
"id": "660bc1fd",
158+
"metadata": {},
159+
"source": [
160+
"## 10. What is the data type of None?\n"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"id": "8072279f",
166+
"metadata": {},
167+
"source": [
168+
"</ul>\n",
169+
"\n",
170+
"<li>None keyword is an object and is a data type of none type class.</li>\n",
171+
"<li>None datatype doesn’t contain any value.</li>\n",
172+
"<li>None keyword is used to define a null variable or object.</li>\n",
173+
"<li>None keyword is immutable.</li>\n",
174+
"</ul\n",
175+
"\n",
176+
"The data type of None is NoneType."
177+
]
178+
},
179+
{
180+
"cell_type": "markdown",
181+
"id": "fac27ec1",
182+
"metadata": {},
183+
"source": [
184+
"## 11. What does the sentence import areallyourpetsnamederic do?\n"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"id": "66f00efb",
190+
"metadata": {},
191+
"source": [
192+
"this sentence imports the module “areallyourpetsnamederic “"
193+
]
194+
},
195+
{
196+
"cell_type": "markdown",
197+
"id": "bc2d004e",
198+
"metadata": {},
199+
"source": [
200+
"## 12. If you had a bacon() feature in a spam module, what would you call it after importing spam?\n"
201+
]
202+
},
203+
{
204+
"cell_type": "markdown",
205+
"id": "dad916c9",
206+
"metadata": {},
207+
"source": [
208+
"This function can be called with spam.bacon()."
209+
]
210+
},
211+
{
212+
"cell_type": "markdown",
213+
"id": "07d5a52e",
214+
"metadata": {},
215+
"source": [
216+
"## 13. What can you do to save a programme from crashing if it encounters an error?"
217+
]
218+
},
219+
{
220+
"cell_type": "markdown",
221+
"id": "b22e1051",
222+
"metadata": {},
223+
"source": [
224+
"<li>error handling can be used to notify the user of why the error occurred and gracefully exit the process that caused the error.</li>\n",
225+
"<li>Place the line of code that might cause an error in a try clause.</li>"
226+
]
227+
},
228+
{
229+
"cell_type": "markdown",
230+
"id": "f4b77fed",
231+
"metadata": {},
232+
"source": [
233+
"## 14. What is the purpose of the try clause? What is the purpose of the except clause?"
234+
]
235+
},
236+
{
237+
"cell_type": "markdown",
238+
"id": "fd5129b9",
239+
"metadata": {},
240+
"source": [
241+
"TRY CLAUSE: try clause is used when you think that program can crash so you try to run the program and it crashes it wont disturb other part of program\n",
242+
"\n",
243+
"EXCEPT CLAUSE: except clause is used when you are trying a certain part of program but it fails so it used as a response to exception."
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": null,
249+
"id": "9b521482",
250+
"metadata": {},
251+
"outputs": [],
252+
"source": []
253+
}
254+
],
255+
"metadata": {
256+
"kernelspec": {
257+
"display_name": "Python 3",
258+
"language": "python",
259+
"name": "python3"
260+
},
261+
"language_info": {
262+
"codemirror_mode": {
263+
"name": "ipython",
264+
"version": 3
265+
},
266+
"file_extension": ".py",
267+
"mimetype": "text/x-python",
268+
"name": "python",
269+
"nbconvert_exporter": "python",
270+
"pygments_lexer": "ipython3",
271+
"version": "3.8.8"
272+
}
273+
},
274+
"nbformat": 4,
275+
"nbformat_minor": 5
276+
}

0 commit comments

Comments
 (0)