|
38 | 38 | "source": [ |
39 | 39 | "Double Click HERE to edit this markdown cell and write answers.\n", |
40 | 40 | "\n", |
41 | | - "Numbers:\n", |
| 41 | + "Numbers: Integers (1) / Floating Point (1.1)\n", |
42 | 42 | "\n", |
43 | | - "Strings:\n", |
| 43 | + "Strings: Ordered Sequence of Characters\n", |
44 | 44 | "\n", |
45 | | - "Lists:\n", |
| 45 | + "Lists: Mutable Ordered Sequence of Objects\n", |
46 | 46 | "\n", |
47 | | - "Tuples:\n", |
| 47 | + "Tuples: Immutable Ordered Sequence of Objects\n", |
48 | 48 | "\n", |
49 | | - "Dictionaries:\n" |
| 49 | + "Dictionaries: Unordered Key-Value Pairs \n" |
50 | 50 | ] |
51 | 51 | }, |
52 | 52 | { |
|
67 | 67 | "collapsed": true |
68 | 68 | }, |
69 | 69 | "outputs": [], |
70 | | - "source": [] |
| 70 | + "source": [ |
| 71 | + "(60+(10**2)/4*7)-134.75" |
| 72 | + ] |
71 | 73 | }, |
72 | 74 | { |
73 | 75 | "cell_type": "markdown", |
|
76 | 78 | "Answer these 3 questions without typing code. Then type code to check your answer.\n", |
77 | 79 | "\n", |
78 | 80 | " What is the value of the expression 4 * (6 + 5)\n", |
79 | | - " \n", |
| 81 | + " 44\n", |
80 | 82 | " What is the value of the expression 4 * 6 + 5 \n", |
81 | | - " \n", |
82 | | - " What is the value of the expression 4 + 6 * 5 " |
| 83 | + " 29\n", |
| 84 | + " What is the value of the expression 4 + 6 * 5\n", |
| 85 | + " 34 " |
83 | 86 | ] |
84 | 87 | }, |
85 | 88 | { |
|
95 | 98 | "cell_type": "markdown", |
96 | 99 | "metadata": {}, |
97 | 100 | "source": [ |
98 | | - "What is the *type* of the result of the expression 3 + 1.5 + 4?<br><br>" |
| 101 | + "What is the *type* of the result of the expression 3 + 1.5 + 4?<br><br>\n", |
| 102 | + "Float or Floating Point" |
99 | 103 | ] |
100 | 104 | }, |
101 | 105 | { |
|
113 | 117 | }, |
114 | 118 | "outputs": [], |
115 | 119 | "source": [ |
116 | | - "# Square root:\n" |
| 120 | + "# Square root: 100 ** 0.5\n" |
117 | 121 | ] |
118 | 122 | }, |
119 | 123 | { |
|
124 | 128 | }, |
125 | 129 | "outputs": [], |
126 | 130 | "source": [ |
127 | | - "# Square:\n" |
| 131 | + "# Square: 10 ** 2\n" |
128 | 132 | ] |
129 | 133 | }, |
130 | 134 | { |
|
151 | 155 | "source": [ |
152 | 156 | "s = 'hello'\n", |
153 | 157 | "# Print out 'e' using indexing\n", |
154 | | - "\n" |
| 158 | + "\n", |
| 159 | + "s[1]" |
155 | 160 | ] |
156 | 161 | }, |
157 | 162 | { |
|
171 | 176 | "source": [ |
172 | 177 | "s ='hello'\n", |
173 | 178 | "# Reverse the string using slicing\n", |
174 | | - "\n" |
| 179 | + "\n", |
| 180 | + "s[::-1]" |
175 | 181 | ] |
176 | 182 | }, |
177 | 183 | { |
|
193 | 199 | "# Print out the 'o'\n", |
194 | 200 | "\n", |
195 | 201 | "# Method 1:\n", |
196 | | - "\n" |
| 202 | + "\n", |
| 203 | + "s[4]" |
197 | 204 | ] |
198 | 205 | }, |
199 | 206 | { |
|
205 | 212 | "outputs": [], |
206 | 213 | "source": [ |
207 | 214 | "# Method 2:\n", |
208 | | - "\n" |
| 215 | + "\n", |
| 216 | + "s[-1]" |
209 | 217 | ] |
210 | 218 | }, |
211 | 219 | { |
|
230 | 238 | }, |
231 | 239 | "outputs": [], |
232 | 240 | "source": [ |
233 | | - "# Method 1:\n" |
| 241 | + "# Method 1:\n", |
| 242 | + "list=[0,0,0]\n", |
| 243 | + "list" |
234 | 244 | ] |
235 | 245 | }, |
236 | 246 | { |
|
241 | 251 | }, |
242 | 252 | "outputs": [], |
243 | 253 | "source": [ |
244 | | - "# Method 2:\n" |
| 254 | + "# Method 2:\n", |
| 255 | + "[0]*3" |
245 | 256 | ] |
246 | 257 | }, |
247 | 258 | { |
|
260 | 271 | "outputs": [], |
261 | 272 | "source": [ |
262 | 273 | "list3 = [1,2,[3,4,'hello']]\n", |
263 | | - "\n" |
| 274 | + "\n", |
| 275 | + "list3[2][2] = 'goodbye'" |
264 | 276 | ] |
265 | 277 | }, |
266 | 278 | { |
|
278 | 290 | }, |
279 | 291 | "outputs": [], |
280 | 292 | "source": [ |
| 293 | + "#Method1\n", |
| 294 | + "\n", |
281 | 295 | "list4 = [5,3,4,6,1]\n", |
282 | | - "\n" |
| 296 | + "\n", |
| 297 | + "sorted(list4)" |
| 298 | + ] |
| 299 | + }, |
| 300 | + { |
| 301 | + "cell_type": "code", |
| 302 | + "execution_count": null, |
| 303 | + "metadata": {}, |
| 304 | + "outputs": [], |
| 305 | + "source": [ |
| 306 | + "#Method2\n", |
| 307 | + "\n", |
| 308 | + "list4.sort()\n", |
| 309 | + "list4" |
283 | 310 | ] |
284 | 311 | }, |
285 | 312 | { |
|
305 | 332 | "outputs": [], |
306 | 333 | "source": [ |
307 | 334 | "d = {'simple_key':'hello'}\n", |
308 | | - "# Grab 'hello'\n" |
| 335 | + "# Grab 'hello'\n", |
| 336 | + "\n", |
| 337 | + "d['simple_key']" |
309 | 338 | ] |
310 | 339 | }, |
311 | 340 | { |
|
317 | 346 | "outputs": [], |
318 | 347 | "source": [ |
319 | 348 | "d = {'k1':{'k2':'hello'}}\n", |
320 | | - "# Grab 'hello'\n" |
| 349 | + "# Grab 'hello'\n", |
| 350 | + "\n", |
| 351 | + "d['k1']['k2']" |
321 | 352 | ] |
322 | 353 | }, |
323 | 354 | { |
|
331 | 362 | "# Getting a little tricker\n", |
332 | 363 | "d = {'k1':[{'nest_key':['this is deep',['hello']]}]}\n", |
333 | 364 | "\n", |
334 | | - "#Grab hello\n" |
| 365 | + "#Grab hello\n", |
| 366 | + "\n", |
| 367 | + "d['k1'][0]['nest_key'][1][0]" |
335 | 368 | ] |
336 | 369 | }, |
337 | 370 | { |
|
343 | 376 | "outputs": [], |
344 | 377 | "source": [ |
345 | 378 | "# This will be hard and annoying!\n", |
346 | | - "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}" |
| 379 | + "d = {'k1':[1,2,{'k2':['this is tricky',{'tough':[1,2,['hello']]}]}]}\n", |
| 380 | + "\n", |
| 381 | + "d['k1'][2]['k2'][1]['tough'][2][0]" |
347 | 382 | ] |
348 | 383 | }, |
349 | 384 | { |
350 | 385 | "cell_type": "markdown", |
351 | 386 | "metadata": {}, |
352 | 387 | "source": [ |
353 | | - "Can you sort a dictionary? Why or why not?<br><br>" |
| 388 | + "Can you sort a dictionary? Why or why not?<br><br>\n", |
| 389 | + "\n", |
| 390 | + "No (mappings, not a sequence)" |
354 | 391 | ] |
355 | 392 | }, |
356 | 393 | { |
|
364 | 401 | "cell_type": "markdown", |
365 | 402 | "metadata": {}, |
366 | 403 | "source": [ |
367 | | - "What is the major difference between tuples and lists?<br><br>" |
| 404 | + "What is the major difference between tuples and lists?<br><br>\n", |
| 405 | + "\n", |
| 406 | + "Tuples are immutable" |
368 | 407 | ] |
369 | 408 | }, |
370 | 409 | { |
371 | 410 | "cell_type": "markdown", |
372 | 411 | "metadata": {}, |
373 | 412 | "source": [ |
374 | | - "How do you create a tuple?<br><br>" |
| 413 | + "How do you create a tuple?<br><br>\n", |
| 414 | + "\n", |
| 415 | + "Variable = (1,2,3)\n", |
| 416 | + " - Parenthesis" |
375 | 417 | ] |
376 | 418 | }, |
377 | 419 | { |
|
385 | 427 | "cell_type": "markdown", |
386 | 428 | "metadata": {}, |
387 | 429 | "source": [ |
388 | | - "What is unique about a set?<br><br>" |
| 430 | + "What is unique about a set?<br><br>\n", |
| 431 | + "\n", |
| 432 | + "No Duplicates" |
389 | 433 | ] |
390 | 434 | }, |
391 | 435 | { |
|
405 | 449 | "source": [ |
406 | 450 | "list5 = [1,2,2,33,4,4,11,22,3,3,2]\n", |
407 | 451 | "\n", |
408 | | - "\n" |
| 452 | + "set(list5)\n" |
409 | 453 | ] |
410 | 454 | }, |
411 | 455 | { |
|
474 | 518 | "outputs": [], |
475 | 519 | "source": [ |
476 | 520 | "# Answer before running cell\n", |
477 | | - "2 > 3" |
| 521 | + "2 > 3\n", |
| 522 | + "\n", |
| 523 | + "False" |
478 | 524 | ] |
479 | 525 | }, |
480 | 526 | { |
|
486 | 532 | "outputs": [], |
487 | 533 | "source": [ |
488 | 534 | "# Answer before running cell\n", |
489 | | - "3 <= 2" |
| 535 | + "3 <= 2\n", |
| 536 | + "\n", |
| 537 | + "False" |
490 | 538 | ] |
491 | 539 | }, |
492 | 540 | { |
|
498 | 546 | "outputs": [], |
499 | 547 | "source": [ |
500 | 548 | "# Answer before running cell\n", |
501 | | - "3 == 2.0" |
| 549 | + "3 == 2.0\n", |
| 550 | + "\n", |
| 551 | + "False" |
502 | 552 | ] |
503 | 553 | }, |
504 | 554 | { |
|
510 | 560 | "outputs": [], |
511 | 561 | "source": [ |
512 | 562 | "# Answer before running cell\n", |
513 | | - "3.0 == 3" |
| 563 | + "3.0 == 3\n", |
| 564 | + "\n", |
| 565 | + "True" |
514 | 566 | ] |
515 | 567 | }, |
516 | 568 | { |
|
522 | 574 | "outputs": [], |
523 | 575 | "source": [ |
524 | 576 | "# Answer before running cell\n", |
525 | | - "4**0.5 != 2" |
| 577 | + "4**0.5 != 2\n", |
| 578 | + "\n", |
| 579 | + "False" |
526 | 580 | ] |
527 | 581 | }, |
528 | 582 | { |
|
545 | 599 | "l_two = [1,2,{'k1':4}]\n", |
546 | 600 | "\n", |
547 | 601 | "# True or False?\n", |
548 | | - "l_one[2][0] >= l_two[2]['k1']" |
| 602 | + "l_one[2][0] >= l_two[2]['k1']\n", |
| 603 | + "\n", |
| 604 | + "Is 3 > 4? FALSE" |
549 | 605 | ] |
550 | 606 | }, |
551 | 607 | { |
|
564 | 620 | "name": "python3" |
565 | 621 | }, |
566 | 622 | "language_info": { |
567 | | - "codemirror_mode": { |
568 | | - "name": "ipython", |
569 | | - "version": 3 |
570 | | - }, |
571 | | - "file_extension": ".py", |
572 | | - "mimetype": "text/x-python", |
573 | 623 | "name": "python", |
574 | | - "nbconvert_exporter": "python", |
575 | | - "pygments_lexer": "ipython3", |
576 | | - "version": "3.6.6" |
| 624 | + "version": "3.12.5" |
577 | 625 | } |
578 | 626 | }, |
579 | 627 | "nbformat": 4, |
|
0 commit comments