Skip to content

Commit 70dd69e

Browse files
committed
more notebook work. Starting to struggle, need to spend more time on problems
1 parent 3369e3d commit 70dd69e

7 files changed

+700
-163
lines changed

Python Absolute Beginner/Module_4.0_Tutorials_Nested_Conditionals.ipynb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,18 @@
959959
},
960960
{
961961
"cell_type": "code",
962-
"execution_count": null,
962+
"execution_count": 47,
963963
"metadata": {},
964-
"outputs": [],
964+
"outputs": [
965+
{
966+
"name": "stdout",
967+
"output_type": "stream",
968+
"text": [
969+
"\n",
970+
"Zac has been entered as first name\n"
971+
]
972+
}
973+
],
965974
"source": [
966975
"# review and run example that loops until a valid first name format is entered\n",
967976
"student_fname = \".\"\n",
@@ -1051,7 +1060,7 @@
10511060
"metadata": {
10521061
"anaconda-cloud": {},
10531062
"kernelspec": {
1054-
"display_name": "Python 3",
1063+
"display_name": "Python 3.9.12 ('base')",
10551064
"language": "python",
10561065
"name": "python3"
10571066
},
@@ -1065,7 +1074,12 @@
10651074
"name": "python",
10661075
"nbconvert_exporter": "python",
10671076
"pygments_lexer": "ipython3",
1068-
"version": "3.8.8"
1077+
"version": "3.9.12"
1078+
},
1079+
"vscode": {
1080+
"interpreter": {
1081+
"hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261"
1082+
}
10691083
}
10701084
},
10711085
"nbformat": 4,

Python Absolute Beginner/Module_4.1_Practice.ipynb

Lines changed: 120 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,63 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": null,
24+
"execution_count": 2,
2525
"metadata": {},
26-
"outputs": [],
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"The new line character is \"\\n\"\n"
32+
]
33+
}
34+
],
2735
"source": [
2836
"# [ ] print a string that outputs the following exactly: The new line character is \"\\n\"\n",
29-
"\n"
37+
"print('The new line character is \"\\\\n\"')\n"
3038
]
3139
},
3240
{
3341
"cell_type": "code",
34-
"execution_count": null,
42+
"execution_count": 5,
3543
"metadata": {},
36-
"outputs": [],
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
"\"That's how we escape\"\n"
50+
]
51+
}
52+
],
3753
"source": [
3854
"# [ ] print output that is exactly (with quotes): \"That's how we escape!\"\n",
39-
"\n"
55+
"print(\"\\\"That's how we escape\\\"\")\n"
4056
]
4157
},
4258
{
4359
"cell_type": "code",
44-
"execution_count": null,
60+
"execution_count": 6,
4561
"metadata": {},
46-
"outputs": [],
62+
"outputs": [
63+
{
64+
"name": "stdout",
65+
"output_type": "stream",
66+
"text": [
67+
"#1 one\n",
68+
"#22 two\n",
69+
"#333 three\n"
70+
]
71+
}
72+
],
4773
"source": [
4874
"# [ ] with only 1 print statement and using No Space Characters, output the text commented below \n",
4975
"\n",
5076
"# 1 one\n",
5177
"# 22 two\n",
5278
"# 333 three\n",
53-
"\n"
79+
"\n",
80+
"print(\"#1 one\\n#22 two\\n#333 three\")"
5481
]
5582
},
5683
{
@@ -68,11 +95,30 @@
6895
},
6996
{
7097
"cell_type": "code",
71-
"execution_count": null,
98+
"execution_count": 12,
7299
"metadata": {},
73-
"outputs": [],
100+
"outputs": [
101+
{
102+
"name": "stdout",
103+
"output_type": "stream",
104+
"text": [
105+
"'\"Don't hate the player, hate the game\"'\n"
106+
]
107+
}
108+
],
74109
"source": [
75110
"# [ ] create and test quote_me()\n",
111+
"def quote_me() :\n",
112+
" quote= input(\"what do you have to say for yourself?\")\n",
113+
" if quote.startswith('\"') :\n",
114+
" quote= \"\\'\" + quote + \"\\'\"\n",
115+
" \n",
116+
" else :\n",
117+
" quote= \"\\\"\" + quote + \"\\\"\"\n",
118+
" print(quote) \n",
119+
" \n",
120+
"quote_me()\n",
121+
"\n",
76122
"\n",
77123
"\n"
78124
]
@@ -230,16 +276,41 @@
230276
},
231277
{
232278
"cell_type": "code",
233-
"execution_count": null,
279+
"execution_count": 27,
234280
"metadata": {},
235-
"outputs": [],
281+
"outputs": [
282+
{
283+
"name": "stdout",
284+
"output_type": "stream",
285+
"text": [
286+
"you win!\n",
287+
"you win!\n",
288+
"you win!\n",
289+
"you win!\n",
290+
"you win!\n"
291+
]
292+
},
293+
{
294+
"ename": "KeyboardInterrupt",
295+
"evalue": "Interrupted by user",
296+
"output_type": "error",
297+
"traceback": [
298+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
299+
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
300+
"\u001b[1;32mc:\\Users\\Four\\Documents\\GitHub\\pythonteachingcode\\Python Absolute Beginner\\Module_4.1_Practice.ipynb Cell 20'\u001b[0m in \u001b[0;36m<cell line: 4>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Four/Documents/GitHub/pythonteachingcode/Python%20Absolute%20Beginner/Module_4.1_Practice.ipynb#ch0000019?line=7'>8</a>\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Four/Documents/GitHub/pythonteachingcode/Python%20Absolute%20Beginner/Module_4.1_Practice.ipynb#ch0000019?line=8'>9</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39msorry, not a winner.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m---> <a href='vscode-notebook-cell:/c%3A/Users/Four/Documents/GitHub/pythonteachingcode/Python%20Absolute%20Beginner/Module_4.1_Practice.ipynb#ch0000019?line=9'>10</a>\u001b[0m tickets \u001b[39m=\u001b[39m \u001b[39mint\u001b[39m(\u001b[39minput\u001b[39;49m(\u001b[39m\"\u001b[39;49m\u001b[39menter tickets remaining (0 to quit): \u001b[39;49m\u001b[39m\"\u001b[39;49m))\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/Four/Documents/GitHub/pythonteachingcode/Python%20Absolute%20Beginner/Module_4.1_Practice.ipynb#ch0000019?line=11'>12</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mGame ended\u001b[39m\u001b[39m\"\u001b[39m)\n",
301+
"File \u001b[1;32mc:\\Users\\Four\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1075\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m 1071\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_allow_stdin:\n\u001b[0;32m 1072\u001b[0m \u001b[39mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m 1073\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 1074\u001b[0m )\n\u001b[1;32m-> 1075\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_input_request(\n\u001b[0;32m 1076\u001b[0m \u001b[39mstr\u001b[39;49m(prompt),\n\u001b[0;32m 1077\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_parent_ident[\u001b[39m\"\u001b[39;49m\u001b[39mshell\u001b[39;49m\u001b[39m\"\u001b[39;49m],\n\u001b[0;32m 1078\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mget_parent(\u001b[39m\"\u001b[39;49m\u001b[39mshell\u001b[39;49m\u001b[39m\"\u001b[39;49m),\n\u001b[0;32m 1079\u001b[0m password\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 1080\u001b[0m )\n",
302+
"File \u001b[1;32mc:\\Users\\Four\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m 1117\u001b[0m \u001b[39mbreak\u001b[39;00m\n\u001b[0;32m 1118\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m 1119\u001b[0m \u001b[39m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mKeyboardInterrupt\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mInterrupted by user\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[0;32m 1121\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m:\n\u001b[0;32m 1122\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlog\u001b[39m.\u001b[39mwarning(\u001b[39m\"\u001b[39m\u001b[39mInvalid Message:\u001b[39m\u001b[39m\"\u001b[39m, exc_info\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n",
303+
"\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
304+
]
305+
}
306+
],
236307
"source": [
237308
"# [ ] review the code, run, fix the error\n",
238-
"tickets = input(\"enter tickets remaining (0 to quit): \")\n",
309+
"tickets = int(input(\"enter tickets remaining (0 to quit): \"))\n",
239310
"\n",
240-
"while tickets > 0:\n",
311+
"while int(tickets) > 0:\n",
241312
" # if tickets are multiple of 3 then \"winner\"\n",
242-
" if int(tickets/3) == tickets/3:\n",
313+
" if tickets/3 == \n",
243314
" print(\"you win!\")\n",
244315
" else:\n",
245316
" print(\"sorry, not a winner.\")\n",
@@ -265,13 +336,36 @@
265336
},
266337
{
267338
"cell_type": "code",
268-
"execution_count": 1,
339+
"execution_count": 32,
269340
"metadata": {},
270-
"outputs": [],
341+
"outputs": [
342+
{
343+
"name": "stdout",
344+
"output_type": "stream",
345+
"text": [
346+
"What is my name?\n",
347+
"correct!\n",
348+
"What programming language is this question written in?\n",
349+
"correct!\n"
350+
]
351+
}
352+
],
271353
"source": [
272354
"# Create quiz_item() and 2 or more quiz questions that call quiz_item()\n",
273355
"\n",
274-
"#quiz_item()has 2 parameter strings: question and solution\n"
356+
"#quiz_item()has 2 parameter strings: question and solution\n",
357+
"def quiz_item(question, solution):\n",
358+
" while True:\n",
359+
" print(question)\n",
360+
" answer=input(\"Enter your answer\")\n",
361+
" if answer.lower()==solution:\n",
362+
" print(\"correct!\")\n",
363+
" break\n",
364+
" else:\n",
365+
" print(\"Try again\")\n",
366+
"quiz_item(\"What is my name?\",\"zac\")\n",
367+
"quiz_item(\"What programming language is this question written in?\",\"python\")\n",
368+
" "
275369
]
276370
},
277371
{
@@ -287,7 +381,7 @@
287381
"metadata": {
288382
"anaconda-cloud": {},
289383
"kernelspec": {
290-
"display_name": "Python 3",
384+
"display_name": "Python 3.9.12 ('base')",
291385
"language": "python",
292386
"name": "python3"
293387
},
@@ -301,7 +395,12 @@
301395
"name": "python",
302396
"nbconvert_exporter": "python",
303397
"pygments_lexer": "ipython3",
304-
"version": "3.8.8"
398+
"version": "3.9.12"
399+
},
400+
"vscode": {
401+
"interpreter": {
402+
"hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261"
403+
}
305404
}
306405
},
307406
"nbformat": 4,

Python Absolute Beginner/Module_4.2_Required_Code.ipynb

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"cells": [
33
{
4+
"cell_type": "markdown",
45
"metadata": {
56
"collapsed": true
67
},
7-
"cell_type": "markdown",
88
"source": [
99
"# Module 4 Required Coding Activity \n",
1010
"Introduction to Python Unit 1 \n",
@@ -83,47 +83,83 @@
8383
]
8484
},
8585
{
86+
"cell_type": "code",
87+
"execution_count": 1,
8688
"metadata": {
8789
"trusted": false
8890
},
89-
"cell_type": "code",
91+
"outputs": [
92+
{
93+
"name": "stdout",
94+
"output_type": "stream",
95+
"text": [
96+
"10 is a small number\n"
97+
]
98+
}
99+
],
90100
"source": [
91101
"# [ ] create, call and test the str_analysis() function \n",
92102
"\n",
103+
"def str_analysis():\n",
104+
" while True :\n",
105+
" string= input(\"Enter word or integer\")\n",
106+
" if string.isdigit() :\n",
107+
" if int(string) > 99:\n",
108+
" print(string,\"is a big number\")\n",
109+
" break\n",
110+
" else :\n",
111+
" print(string,\"is a small number\")\n",
112+
" break\n",
113+
" elif string.isalpha() :\n",
114+
" print(string, \"is all alphabetical\")\n",
115+
" break\n",
116+
" \n",
117+
" elif string == \"\" :\n",
118+
" print(\"Invalid Input, type a word or integer\")\n",
119+
" else :\n",
120+
" print(string, \"is made up of mixed characters\")\n",
121+
" break\n",
122+
"\n",
123+
"str_analysis()\n",
124+
"\n",
125+
" \n",
93126
"\n",
94127
"\n",
95128
"\n"
96-
],
97-
"execution_count": null,
98-
"outputs": []
129+
]
99130
},
100131
{
101-
"metadata": {},
102132
"cell_type": "markdown",
133+
"metadata": {},
103134
"source": [
104135
"Submit this by creating a python file (.py) and submitting it in D2L. Be sure to test that it works."
105136
]
106137
}
107138
],
108139
"metadata": {
109140
"kernelspec": {
110-
"name": "python3",
111-
"display_name": "Python 3",
112-
"language": "python"
141+
"display_name": "Python 3.9.12 ('base')",
142+
"language": "python",
143+
"name": "python3"
113144
},
114145
"language_info": {
146+
"codemirror_mode": {
147+
"name": "ipython",
148+
"version": 3
149+
},
150+
"file_extension": ".py",
115151
"mimetype": "text/x-python",
116-
"nbconvert_exporter": "python",
117152
"name": "python",
118-
"file_extension": ".py",
119-
"version": "3.5.4",
153+
"nbconvert_exporter": "python",
120154
"pygments_lexer": "ipython3",
121-
"codemirror_mode": {
122-
"version": 3,
123-
"name": "ipython"
155+
"version": "3.9.12"
156+
},
157+
"vscode": {
158+
"interpreter": {
159+
"hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261"
124160
}
125161
}
126162
},
127163
"nbformat": 4,
128164
"nbformat_minor": 1
129-
}
165+
}

0 commit comments

Comments
 (0)