Skip to content

Commit 3369e3d

Browse files
committed
Homeworks
1 parent 05f394e commit 3369e3d

File tree

3 files changed

+435
-64
lines changed

3 files changed

+435
-64
lines changed

Python Absolute Beginner/Module_3.1_Practice.ipynb

Lines changed: 127 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
},
1818
{
1919
"cell_type": "code",
20-
"execution_count": 7,
20+
"execution_count": 3,
2121
"metadata": {},
2222
"outputs": [
2323
{
2424
"name": "stdout",
2525
"output_type": "stream",
2626
"text": [
27-
"Input your age (use only whole numbers): 23\n",
2827
"Age's first type is: <class 'int'>\n",
2928
"Age's second type is: <class 'int'>\n",
30-
"In ten years you will be 33.\n"
29+
"It is good to be 11.\n"
3130
]
3231
}
3332
],
@@ -51,16 +50,32 @@
5150
},
5251
{
5352
"cell_type": "code",
54-
"execution_count": null,
53+
"execution_count": 9,
5554
"metadata": {
5655
"collapsed": true
5756
},
58-
"outputs": [],
57+
"outputs": [
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
"only int is accepted\n"
63+
]
64+
}
65+
],
5966
"source": [
6067
"# [ ] input a number \n",
68+
"num_1= input(\"Enter an integer value\")\n",
6169
"# if number IS a digit string then cast to int\n",
62-
"# print number \"greater than 100 is\" True/False\n",
63-
"# if number is NOT a digit string then message the user that \"only int is accepted\"\n",
70+
"if num_1.isdigit() :\n",
71+
" num_1 = int(num_1)\n",
72+
" # print number \"greater than 100 is\" True/False\n",
73+
" print(\"greater than 100 is\" , num_1 > 100)\n",
74+
"else :\n",
75+
" # if number is NOT a digit string then message the user that \"only int is accepted\"\n",
76+
" print(\"only int is accepted\")\n",
77+
"\n",
78+
"\n",
6479
"\n",
6580
"\n"
6681
]
@@ -262,56 +277,140 @@
262277
},
263278
{
264279
"cell_type": "code",
265-
"execution_count": null,
280+
"execution_count": 10,
266281
"metadata": {},
267-
"outputs": [],
282+
"outputs": [
283+
{
284+
"name": "stdout",
285+
"output_type": "stream",
286+
"text": [
287+
"4\n"
288+
]
289+
}
290+
],
268291
"source": [
269292
"# [ ] add 2 numbers from input using a cast to integer and display the answer \n",
270-
"\n"
293+
"\n",
294+
"num_1 = input(\"enter 2 integers\")\n",
295+
"num_2 = input(\"enter 2 integers\")\n",
296+
"num_3 = int(num_1) + int(num_2)\n",
297+
"print(num_3)"
271298
]
272299
},
273300
{
274301
"cell_type": "code",
275-
"execution_count": null,
302+
"execution_count": 11,
276303
"metadata": {},
277-
"outputs": [],
304+
"outputs": [
305+
{
306+
"name": "stdout",
307+
"output_type": "stream",
308+
"text": [
309+
"the answer is... 16\n"
310+
]
311+
}
312+
],
278313
"source": [
279314
"# [ ] Multiply 2 numbers from input using cast and save the answer as part of a string \"the answer is...\"\n",
280315
"# display the string using print\n",
281-
"\n"
316+
"num_1 = input(\"enter 2 integers\")\n",
317+
"num_2 = input(\"enter 2 integers\")\n",
318+
"num_3 = int(num_1) * int(num_2)\n",
319+
"print(\"the answer is...\", num_3)\n"
282320
]
283321
},
284322
{
285323
"cell_type": "code",
286-
"execution_count": null,
324+
"execution_count": 13,
287325
"metadata": {},
288-
"outputs": [],
326+
"outputs": [
327+
{
328+
"name": "stdout",
329+
"output_type": "stream",
330+
"text": [
331+
"2.0\n"
332+
]
333+
}
334+
],
289335
"source": [
290336
"# [ ] get input of 2 numbers and display the average: (num1 + num2) divided by 2\n",
291-
"\n"
337+
"num_1 = input(\"enter 2 integers\")\n",
338+
"num_2 = input(\"enter 2 integers\")\n",
339+
"num_3 = (int(num_1) + int(num_2)) / 2\n",
340+
"print(num_3)"
292341
]
293342
},
294343
{
295344
"cell_type": "code",
296-
"execution_count": null,
345+
"execution_count": 15,
297346
"metadata": {},
298-
"outputs": [],
347+
"outputs": [
348+
{
349+
"name": "stdout",
350+
"output_type": "stream",
351+
"text": [
352+
"2\n"
353+
]
354+
}
355+
],
299356
"source": [
300357
"# [ ] get input of 2 numbers and subtract the largest from the smallest (use an if statement to see which is larger)\n",
301358
"# show the answer\n",
359+
"num_1 = input(\"enter 2 integers\")\n",
360+
"num_2 = input(\"enter 2 integers\")\n",
361+
"if num_1 > num_2 :\n",
362+
" num_3 = int(num_1) - int(num_2)\n",
363+
" print(num_3)\n",
364+
"elif num_1 < num_2 :\n",
365+
" num_3 = int(num_2) - int(num_1)\n",
366+
" print(num_3)\n",
367+
"elif num_1 == num_2 :\n",
368+
" num_3 = int(num_2) - int(num_1)\n",
369+
" print(num_3)\n",
370+
"else :\n",
371+
" print(\"invalid input\")\n",
302372
"\n"
303373
]
304374
},
305375
{
306376
"cell_type": "code",
307-
"execution_count": null,
377+
"execution_count": 38,
308378
"metadata": {},
309-
"outputs": [],
379+
"outputs": [
380+
{
381+
"name": "stdout",
382+
"output_type": "stream",
383+
"text": [
384+
"5\n"
385+
]
386+
}
387+
],
310388
"source": [
311389
"# [ ] Divide a larger number by a smaller number and print the integer part of the result\n",
312390
"# don't divide by zero! if a zero is input make the result zero\n",
313391
"# [ ] cast the answer to an integer to cut off the decimals and print the result\n",
314-
"\n"
392+
"\n",
393+
"#get user input\n",
394+
"num_1 = input(\"enter 2 integers\")\n",
395+
"num_2 = input(\"enter 2 integers\")\n",
396+
"#change to int so or statement works properly\n",
397+
"num_1 = int(num_1)\n",
398+
"num_2 = int(num_2)\n",
399+
"#divide by 0 check\n",
400+
"if num_1 == 0 or num_2 == 0 :\n",
401+
" print(\"0\")\n",
402+
"\n",
403+
"elif num_1 > num_2 :\n",
404+
" num_3 = int(num_1) / int(num_2)\n",
405+
" num_3 = int(num_3)\n",
406+
" print(num_3)\n",
407+
"elif num_1 < num_2 :\n",
408+
" num_3 = int(num_2) / int(num_1)\n",
409+
" num_3 = int(num_3)\n",
410+
" print(num_3)\n",
411+
"#int check\n",
412+
"else :\n",
413+
" print(\"invalid input\")\n"
315414
]
316415
},
317416
{
@@ -327,7 +426,7 @@
327426
"metadata": {
328427
"anaconda-cloud": {},
329428
"kernelspec": {
330-
"display_name": "Python 3",
429+
"display_name": "Python 3.9.12 ('base')",
331430
"language": "python",
332431
"name": "python3"
333432
},
@@ -341,7 +440,12 @@
341440
"name": "python",
342441
"nbconvert_exporter": "python",
343442
"pygments_lexer": "ipython3",
344-
"version": "3.8.8"
443+
"version": "3.9.12"
444+
},
445+
"vscode": {
446+
"interpreter": {
447+
"hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261"
448+
}
345449
}
346450
},
347451
"nbformat": 4,

Python Absolute Beginner/Module_3.2_Required_Code.ipynb

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,35 @@
4646
},
4747
{
4848
"cell_type": "code",
49-
"execution_count": null,
49+
"execution_count": 3,
5050
"metadata": {
5151
"trusted": false
5252
},
53-
"outputs": [],
53+
"outputs": [
54+
{
55+
"name": "stdout",
56+
"output_type": "stream",
57+
"text": [
58+
"19.0 costs 56.81\n"
59+
]
60+
}
61+
],
5462
"source": [
55-
"# [ ] create, call and test \n"
63+
"# [ ] create, call and test \n",
64+
"#create\n",
65+
"def cheese_order() :\n",
66+
" x = input(\"Enter cheese order weight (numeric value in pounds):\")\n",
67+
" x = float(x)\n",
68+
" if 1<= x <= 20 :\n",
69+
" price = x * 2.99\n",
70+
" print(x, \"costs\", price)\n",
71+
" elif x>20 :\n",
72+
" print(x, \"is more than currently available stock\")\n",
73+
" elif x<1 :\n",
74+
" print(x, \"is below minimun order amount\")\n",
75+
" else :\n",
76+
" print(\"invalid input (enter numeric value)\")\n",
77+
"cheese_order()\n"
5678
]
5779
},
5880
{
@@ -65,7 +87,7 @@
6587
],
6688
"metadata": {
6789
"kernelspec": {
68-
"display_name": "Python 3",
90+
"display_name": "Python 3.9.12 ('base')",
6991
"language": "python",
7092
"name": "python3"
7193
},
@@ -79,7 +101,12 @@
79101
"name": "python",
80102
"nbconvert_exporter": "python",
81103
"pygments_lexer": "ipython3",
82-
"version": "3.5.4"
104+
"version": "3.9.12"
105+
},
106+
"vscode": {
107+
"interpreter": {
108+
"hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261"
109+
}
83110
}
84111
},
85112
"nbformat": 4,

0 commit comments

Comments
 (0)