Skip to content

Commit 95a2e1e

Browse files
committed
2 parents 3514f4b + 1cc5748 commit 95a2e1e

File tree

81 files changed

+20561
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+20561
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "a7ada90d-95d5-4241-8d0c-866a667b953a",
6+
"metadata": {},
7+
"source": [
8+
"# Specific Errors\n",
9+
"## ZeroDivisionError occurred: integer division or modulo by zero"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"id": "7351890a-92b6-4ab3-bf7a-bc6539d13399",
16+
"metadata": {},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"How many cookies are you baking? 8\n",
23+
"How many people are attending? 3\n"
24+
]
25+
},
26+
{
27+
"name": "stdout",
28+
"output_type": "stream",
29+
"text": [
30+
"\n",
31+
"Let's party! We'll have 3 people attending, they'll each get to eat 2 cookies, and we'll have 2 left over.\n"
32+
]
33+
},
34+
{
35+
"name": "stdout",
36+
"output_type": "stream",
37+
"text": [
38+
"\n",
39+
"Would you like to party more? (y or n) y\n",
40+
"How many cookies are you baking? 8\n",
41+
"How many people are attending? 0\n"
42+
]
43+
},
44+
{
45+
"name": "stdout",
46+
"output_type": "stream",
47+
"text": [
48+
"ZeroDivisionError occurred: integer division or modulo by zero\n"
49+
]
50+
},
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"\n",
56+
"Would you like to party more? (y or n) n\n"
57+
]
58+
}
59+
],
60+
"source": [
61+
"# Define a function called \"party_planner\" to calculate cookie distribution\n",
62+
"def party_planner(cookies, people):\n",
63+
" # Initialize variables for leftovers and cookies per person\n",
64+
" leftovers = None\n",
65+
" num_each = None\n",
66+
"\n",
67+
" try:\n",
68+
" # Calculate the number of cookies each person will get\n",
69+
" num_each = cookies // people\n",
70+
" # Calculate the remaining cookies (leftovers)\n",
71+
" leftovers = cookies % people\n",
72+
" except ZeroDivisionError as e:\n",
73+
" # Handle the case when the number of people is zero\n",
74+
" print(\"ZeroDivisionError occurred: {}\".format(e))\n",
75+
"\n",
76+
" # Return the results\n",
77+
" return num_each, leftovers\n",
78+
"\n",
79+
"# Initialize a flag for party continuation\n",
80+
"lets_party = 'y'\n",
81+
"\n",
82+
"# Continue party planning until the user decides to stop\n",
83+
"while lets_party == 'y':\n",
84+
" # Get input from the user: number of cookies and number of people\n",
85+
" cookies = int(input(\"How many cookies are you baking? \"))\n",
86+
" people = int(input(\"How many people are attending? \"))\n",
87+
"\n",
88+
" # Calculate cookie distribution using the party_planner function\n",
89+
" cookies_each, leftovers = party_planner(cookies, people)\n",
90+
"\n",
91+
" if cookies_each: # If cookies_each is not None (i.e., people > 0)\n",
92+
" # Print the party details\n",
93+
" message = \"\\nLet's party! We'll have {} people attending, they'll each get to eat {} cookies, and we'll have {} left over.\"\n",
94+
" print(message.format(people, cookies_each, leftovers))\n",
95+
"\n",
96+
" # Ask if the user wants to continue party planning\n",
97+
" lets_party = input(\"\\nWould you like to party more? (y or n) \")"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"id": "aaaa4f46-3f5f-4245-b5c6-aa400c548d1f",
103+
"metadata": {},
104+
"source": [
105+
"# No Specific Errors\n",
106+
"## except Exception as e:"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 3,
112+
"id": "2c45c8e0-c0b4-4091-a790-fe809f3dbb2b",
113+
"metadata": {},
114+
"outputs": [
115+
{
116+
"name": "stdout",
117+
"output_type": "stream",
118+
"text": [
119+
"How many cookies are you baking? 8\n",
120+
"How many people are attending? 3\n"
121+
]
122+
},
123+
{
124+
"name": "stdout",
125+
"output_type": "stream",
126+
"text": [
127+
"\n",
128+
"Let's party! We'll have 3 people attending, they'll each get to eat 2 cookies, and we'll have 2 left over.\n"
129+
]
130+
},
131+
{
132+
"name": "stdout",
133+
"output_type": "stream",
134+
"text": [
135+
"\n",
136+
"Would you like to party more? (y or n) y\n",
137+
"How many cookies are you baking? 8\n",
138+
"How many people are attending? 0\n"
139+
]
140+
},
141+
{
142+
"name": "stdout",
143+
"output_type": "stream",
144+
"text": [
145+
"Exception occurred: integer division or modulo by zero\n"
146+
]
147+
},
148+
{
149+
"name": "stdout",
150+
"output_type": "stream",
151+
"text": [
152+
"\n",
153+
"Would you like to party more? (y or n) y\n",
154+
"How many cookies are you baking? 0\n",
155+
"How many people are attending? 3\n",
156+
"\n",
157+
"Would you like to party more? (y or n) n\n"
158+
]
159+
}
160+
],
161+
"source": [
162+
"# Define a function called \"party_planner\" to calculate cookie distribution\n",
163+
"def party_planner(cookies, people):\n",
164+
" # Initialize variables for leftovers and cookies per person\n",
165+
" leftovers = None\n",
166+
" num_each = None\n",
167+
"\n",
168+
" try:\n",
169+
" # Calculate the number of cookies each person will get\n",
170+
" num_each = cookies // people\n",
171+
" # Calculate the remaining cookies (leftovers)\n",
172+
" leftovers = cookies % people\n",
173+
" except Exception as e:\n",
174+
" print(\"Exception occurred: {}\".format(e))\n",
175+
"\n",
176+
" # Return the results\n",
177+
" return num_each, leftovers\n",
178+
"\n",
179+
"# Initialize a flag for party continuation\n",
180+
"lets_party = 'y'\n",
181+
"\n",
182+
"# Continue party planning until the user decides to stop\n",
183+
"while lets_party == 'y':\n",
184+
" # Get input from the user: number of cookies and number of people\n",
185+
" cookies = int(input(\"How many cookies are you baking? \"))\n",
186+
" people = int(input(\"How many people are attending? \"))\n",
187+
"\n",
188+
" # Calculate cookie distribution using the party_planner function\n",
189+
" cookies_each, leftovers = party_planner(cookies, people)\n",
190+
"\n",
191+
" if cookies_each: # If cookies_each is not None (i.e., people > 0)\n",
192+
" # Print the party details\n",
193+
" message = \"\\nLet's party! We'll have {} people attending, they'll each get to eat {} cookies, and we'll have {} left over.\"\n",
194+
" print(message.format(people, cookies_each, leftovers))\n",
195+
"\n",
196+
" # Ask if the user wants to continue party planning\n",
197+
" lets_party = input(\"\\nWould you like to party more? (y or n) \")"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 1,
203+
"id": "10929d6f-85c4-424c-8c21-550cecedd99c",
204+
"metadata": {},
205+
"outputs": [
206+
{
207+
"name": "stdout",
208+
"output_type": "stream",
209+
"text": [
210+
"Selected Jupyter core packages...\n",
211+
"IPython : 8.25.0\n",
212+
"ipykernel : 6.28.0\n",
213+
"ipywidgets : 8.1.2\n",
214+
"jupyter_client : 8.6.0\n",
215+
"jupyter_core : 5.5.0\n",
216+
"jupyter_server : 2.10.0\n",
217+
"jupyterlab : 4.2.3\n",
218+
"nbclient : 0.8.0\n",
219+
"nbconvert : 7.10.0\n",
220+
"nbformat : 5.9.2\n",
221+
"notebook : 7.2.1\n",
222+
"qtconsole : 5.5.1\n",
223+
"traitlets : 5.14.3\n"
224+
]
225+
}
226+
],
227+
"source": [
228+
"!jupyter --version"
229+
]
230+
},
231+
{
232+
"cell_type": "code",
233+
"execution_count": 1,
234+
"id": "d556a636",
235+
"metadata": {},
236+
"outputs": [
237+
{
238+
"name": "stdout",
239+
"output_type": "stream",
240+
"text": [
241+
"Python 3.12.2\n"
242+
]
243+
}
244+
],
245+
"source": [
246+
"!python --version"
247+
]
248+
}
249+
],
250+
"metadata": {
251+
"kernelspec": {
252+
"display_name": "example",
253+
"language": "python",
254+
"name": "python3"
255+
},
256+
"language_info": {
257+
"codemirror_mode": {
258+
"name": "ipython",
259+
"version": 3
260+
},
261+
"file_extension": ".py",
262+
"mimetype": "text/x-python",
263+
"name": "python",
264+
"nbconvert_exporter": "python",
265+
"pygments_lexer": "ipython3",
266+
"version": "3.12.2"
267+
}
268+
},
269+
"nbformat": 4,
270+
"nbformat_minor": 5
271+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "0cd56fe7-d8e8-40d0-978e-b278220e969f",
6+
"metadata": {},
7+
"source": [
8+
"# Task\n",
9+
"### The provided code stub reads two integers from STDIN, a and b. Add code to print three lines where:\n",
10+
"### The first line contains the sum of the two numbers.\n",
11+
"### The second line contains the difference of the two numbers (first - second).\n",
12+
"### The third line contains the product of the two numbers.\n"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 5,
18+
"id": "46cdd745-e6fd-482f-8d5d-4fd090d96585",
19+
"metadata": {},
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"Enter the first integer: 3\n",
26+
"Enter the second integer: 2\n"
27+
]
28+
},
29+
{
30+
"name": "stdout",
31+
"output_type": "stream",
32+
"text": [
33+
"Sum: 5\n",
34+
"Difference: 1\n",
35+
"Product: 6\n"
36+
]
37+
}
38+
],
39+
"source": [
40+
"# If this script is run directly (not imported as a module), execute the following code\n",
41+
"if __name__ == '__main__':\n",
42+
" # Get input for two integers\n",
43+
" a = int(input(\"Enter the first integer: \"))\n",
44+
" b = int(input(\"Enter the second integer: \"))\n",
45+
"\n",
46+
" # Perform arithmetic operations and print the results\n",
47+
" print(\"Sum:\", a + b)\n",
48+
" print(\"Difference:\", a - b)\n",
49+
" print(\"Product:\", a * b)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 1,
55+
"id": "a1600135-e79f-41e3-bce2-f8180a909200",
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
"Selected Jupyter core packages...\n",
63+
"IPython : 8.25.0\n",
64+
"ipykernel : 6.28.0\n",
65+
"ipywidgets : 8.1.2\n",
66+
"jupyter_client : 8.6.0\n",
67+
"jupyter_core : 5.5.0\n",
68+
"jupyter_server : 2.10.0\n",
69+
"jupyterlab : 4.2.3\n",
70+
"nbclient : 0.8.0\n",
71+
"nbconvert : 7.10.0\n",
72+
"nbformat : 5.9.2\n",
73+
"notebook : 7.2.1\n",
74+
"qtconsole : 5.5.1\n",
75+
"traitlets : 5.14.3\n"
76+
]
77+
}
78+
],
79+
"source": [
80+
"!jupyter --version"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 1,
86+
"id": "f0d300ee",
87+
"metadata": {},
88+
"outputs": [
89+
{
90+
"name": "stdout",
91+
"output_type": "stream",
92+
"text": [
93+
"Python 3.12.2\n"
94+
]
95+
}
96+
],
97+
"source": [
98+
"!python --version"
99+
]
100+
}
101+
],
102+
"metadata": {
103+
"kernelspec": {
104+
"display_name": "example",
105+
"language": "python",
106+
"name": "python3"
107+
},
108+
"language_info": {
109+
"codemirror_mode": {
110+
"name": "ipython",
111+
"version": 3
112+
},
113+
"file_extension": ".py",
114+
"mimetype": "text/x-python",
115+
"name": "python",
116+
"nbconvert_exporter": "python",
117+
"pygments_lexer": "ipython3",
118+
"version": "3.12.2"
119+
}
120+
},
121+
"nbformat": 4,
122+
"nbformat_minor": 5
123+
}

0 commit comments

Comments
 (0)