|
1 | 1 | { |
2 | 2 | "metadata": { |
| 3 | + "kernelspec": { |
| 4 | + "codemirror_mode": { |
| 5 | + "name": "ipython", |
| 6 | + "version": 2 |
| 7 | + }, |
| 8 | + "display_name": "IPython (Python 2)", |
| 9 | + "language": "python", |
| 10 | + "name": "python2" |
| 11 | + }, |
3 | 12 | "name": "", |
4 | | - "signature": "sha256:3848b241b0636c3e2673e4668e6bbb1faaf7f14b99a3e00c8373dbe613082288" |
| 13 | + "signature": "sha256:8a8862bd7e9d15dc6e564f2d49fb18a994ecef5e2e72b91161e511e00c6545bd" |
5 | 14 | }, |
6 | 15 | "nbformat": 3, |
7 | 16 | "nbformat_minor": 0, |
|
322 | 331 | "Note that we have a 'cupcakes' parameter as well as a 'guests' parameter. Our function is called and passes in two integer values of 4 and 15. It then prints out the returned result, 60." |
323 | 332 | ] |
324 | 333 | }, |
| 334 | + { |
| 335 | + "cell_type": "heading", |
| 336 | + "level": 3, |
| 337 | + "metadata": {}, |
| 338 | + "source": [ |
| 339 | + "Exercise: Why are functions useful?" |
| 340 | + ] |
| 341 | + }, |
| 342 | + { |
| 343 | + "cell_type": "markdown", |
| 344 | + "metadata": {}, |
| 345 | + "source": [ |
| 346 | + "First, create a new Python script and type in the following." |
| 347 | + ] |
| 348 | + }, |
| 349 | + { |
| 350 | + "cell_type": "code", |
| 351 | + "collapsed": false, |
| 352 | + "input": [ |
| 353 | + "print(\"\\nOn the day of Sept 20, 2014, were you at Intro to Python?\")\n", |
| 354 | + "answer = input(\"Answer truthfully, yes or no --> \")\n", |
| 355 | + "if answer == \"no\":\n", |
| 356 | + " answer = input(\"Are you sure that you weren't? Tell the truth, now --> \")\n", |
| 357 | + "\n", |
| 358 | + "print(\"\\nWere you thinking of skipping the workshop to go to Sea World?\")\n", |
| 359 | + "answer = input(\"Answer truthfully, yes or no --> \")\n", |
| 360 | + "if answer == \"no\":\n", |
| 361 | + " answer = input(\"Are you sure that you weren't? Tell the truth, now --> \")" |
| 362 | + ], |
| 363 | + "language": "python", |
| 364 | + "metadata": {}, |
| 365 | + "outputs": [ |
| 366 | + { |
| 367 | + "output_type": "stream", |
| 368 | + "stream": "stdout", |
| 369 | + "text": [ |
| 370 | + "\n", |
| 371 | + "On the day of Sept 20, 2014, were you at Intro to Python?\n" |
| 372 | + ] |
| 373 | + }, |
| 374 | + { |
| 375 | + "name": "stdout", |
| 376 | + "output_type": "stream", |
| 377 | + "stream": "stdout", |
| 378 | + "text": [ |
| 379 | + "Answer truthfully, yes or no --> yes\n" |
| 380 | + ] |
| 381 | + }, |
| 382 | + { |
| 383 | + "output_type": "stream", |
| 384 | + "stream": "stdout", |
| 385 | + "text": [ |
| 386 | + "\n", |
| 387 | + "Were you thinking of skipping the workshop to go to Sea World?\n" |
| 388 | + ] |
| 389 | + }, |
| 390 | + { |
| 391 | + "name": "stdout", |
| 392 | + "output_type": "stream", |
| 393 | + "stream": "stdout", |
| 394 | + "text": [ |
| 395 | + "Answer truthfully, yes or no --> no\n" |
| 396 | + ] |
| 397 | + } |
| 398 | + ] |
| 399 | + }, |
| 400 | + { |
| 401 | + "cell_type": "markdown", |
| 402 | + "metadata": {}, |
| 403 | + "source": [ |
| 404 | + "Look up when you're done, so that we know to move on to the next step." |
| 405 | + ] |
| 406 | + }, |
| 407 | + { |
| 408 | + "cell_type": "heading", |
| 409 | + "level": 4, |
| 410 | + "metadata": {}, |
| 411 | + "source": [ |
| 412 | + "Was this annoying?" |
| 413 | + ] |
| 414 | + }, |
| 415 | + { |
| 416 | + "cell_type": "markdown", |
| 417 | + "metadata": {}, |
| 418 | + "source": [ |
| 419 | + "Raise your hand if you felt like this exercise was repetitive...TODO" |
| 420 | + ] |
| 421 | + }, |
325 | 422 | { |
326 | 423 | "cell_type": "heading", |
327 | 424 | "level": 2, |
|
0 commit comments