|
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "cell_type": "code", |
24 | | - "execution_count": null, |
| 24 | + "execution_count": 2, |
25 | 25 | "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 | + ], |
27 | 35 | "source": [ |
28 | 36 | "# [ ] 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" |
30 | 38 | ] |
31 | 39 | }, |
32 | 40 | { |
33 | 41 | "cell_type": "code", |
34 | | - "execution_count": null, |
| 42 | + "execution_count": 5, |
35 | 43 | "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 | + ], |
37 | 53 | "source": [ |
38 | 54 | "# [ ] print output that is exactly (with quotes): \"That's how we escape!\"\n", |
39 | | - "\n" |
| 55 | + "print(\"\\\"That's how we escape\\\"\")\n" |
40 | 56 | ] |
41 | 57 | }, |
42 | 58 | { |
43 | 59 | "cell_type": "code", |
44 | | - "execution_count": null, |
| 60 | + "execution_count": 6, |
45 | 61 | "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 | + ], |
47 | 73 | "source": [ |
48 | 74 | "# [ ] with only 1 print statement and using No Space Characters, output the text commented below \n", |
49 | 75 | "\n", |
50 | 76 | "# 1 one\n", |
51 | 77 | "# 22 two\n", |
52 | 78 | "# 333 three\n", |
53 | | - "\n" |
| 79 | + "\n", |
| 80 | + "print(\"#1 one\\n#22 two\\n#333 three\")" |
54 | 81 | ] |
55 | 82 | }, |
56 | 83 | { |
|
68 | 95 | }, |
69 | 96 | { |
70 | 97 | "cell_type": "code", |
71 | | - "execution_count": null, |
| 98 | + "execution_count": 12, |
72 | 99 | "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 | + ], |
74 | 109 | "source": [ |
75 | 110 | "# [ ] 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", |
76 | 122 | "\n", |
77 | 123 | "\n" |
78 | 124 | ] |
|
230 | 276 | }, |
231 | 277 | { |
232 | 278 | "cell_type": "code", |
233 | | - "execution_count": null, |
| 279 | + "execution_count": 27, |
234 | 280 | "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 | + ], |
236 | 307 | "source": [ |
237 | 308 | "# [ ] 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", |
239 | 310 | "\n", |
240 | | - "while tickets > 0:\n", |
| 311 | + "while int(tickets) > 0:\n", |
241 | 312 | " # if tickets are multiple of 3 then \"winner\"\n", |
242 | | - " if int(tickets/3) == tickets/3:\n", |
| 313 | + " if tickets/3 == \n", |
243 | 314 | " print(\"you win!\")\n", |
244 | 315 | " else:\n", |
245 | 316 | " print(\"sorry, not a winner.\")\n", |
|
265 | 336 | }, |
266 | 337 | { |
267 | 338 | "cell_type": "code", |
268 | | - "execution_count": 1, |
| 339 | + "execution_count": 32, |
269 | 340 | "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 | + ], |
271 | 353 | "source": [ |
272 | 354 | "# Create quiz_item() and 2 or more quiz questions that call quiz_item()\n", |
273 | 355 | "\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 | + " " |
275 | 369 | ] |
276 | 370 | }, |
277 | 371 | { |
|
287 | 381 | "metadata": { |
288 | 382 | "anaconda-cloud": {}, |
289 | 383 | "kernelspec": { |
290 | | - "display_name": "Python 3", |
| 384 | + "display_name": "Python 3.9.12 ('base')", |
291 | 385 | "language": "python", |
292 | 386 | "name": "python3" |
293 | 387 | }, |
|
301 | 395 | "name": "python", |
302 | 396 | "nbconvert_exporter": "python", |
303 | 397 | "pygments_lexer": "ipython3", |
304 | | - "version": "3.8.8" |
| 398 | + "version": "3.9.12" |
| 399 | + }, |
| 400 | + "vscode": { |
| 401 | + "interpreter": { |
| 402 | + "hash": "5c63ba0b8f8ad222cc0b06bdcd9f04f10ed843d7f084a2f46bb405b77fc04261" |
| 403 | + } |
305 | 404 | } |
306 | 405 | }, |
307 | 406 | "nbformat": 4, |
|
0 commit comments