|
15 | 15 | "source": [
|
16 | 16 | "#### Answer to A. Python basics, strings, printing (Shaw Exercises 1–10)\n",
|
17 | 17 | "\n",
|
18 |
| - "1. Take the file of Python code you generated in Exercise 1, called `ex1.py`, and run it on the command line. Copy the command and output from your terminal and paste it in a markdown cell in your Jupyter notebook. (Ex1)" |
| 18 | + "Q1. Take the file of Python code you generated in Exercise 1, called `ex1.py`, and run it on the command line. Copy the command and output from your terminal and paste it in a markdown cell in your Jupyter notebook. (Ex1)" |
19 | 19 | ]
|
20 | 20 | },
|
21 | 21 | {
|
|
75 | 75 | "cell_type": "markdown",
|
76 | 76 | "metadata": {},
|
77 | 77 | "source": [
|
78 |
| - "2. Print a sentence that contains a phrase in double quotes; print a sentence that contains an apostrophe. (Ex1)" |
| 78 | + "Q2. Print a sentence that contains a phrase in double quotes; print a sentence that contains an apostrophe. (Ex1)" |
79 | 79 | ]
|
80 | 80 | },
|
81 | 81 | {
|
|
110 | 110 | "cell_type": "markdown",
|
111 | 111 | "metadata": {},
|
112 | 112 | "source": [
|
113 |
| - "3. Deliberately enter five incorrect commands (in separate cells) and interpret the error messages. (Ex1)" |
| 113 | + "Q3. Deliberately enter five incorrect commands (in separate cells) and interpret the error messages. (Ex1)" |
114 | 114 | ]
|
115 | 115 | },
|
116 | 116 | {
|
|
261 | 261 | "cell_type": "markdown",
|
262 | 262 | "metadata": {},
|
263 | 263 | "source": [
|
264 |
| - "4. Add comments to your code in \\#2 and \\#3 explaining what is happening. (Ex2)" |
| 264 | + "Q4. Add comments to your code in \\#2 and \\#3 explaining what is happening. (Ex2)" |
265 | 265 | ]
|
266 | 266 | },
|
267 | 267 | {
|
|
275 | 275 | "cell_type": "markdown",
|
276 | 276 | "metadata": {},
|
277 | 277 | "source": [
|
278 |
| - "5. Write and evaluate five mathematical expressions. (Ex3)" |
| 278 | + "Q5. Write and evaluate five mathematical expressions. (Ex3)" |
279 | 279 | ]
|
280 | 280 | },
|
281 | 281 | {
|
|
444 | 444 | "cell_type": "markdown",
|
445 | 445 | "metadata": {},
|
446 | 446 | "source": [
|
447 |
| - "6. Assign values to three numeric and three string variables. (Ex4)" |
| 447 | + "Q6. Assign values to three numeric and three string variables. (Ex4)" |
448 | 448 | ]
|
449 | 449 | },
|
450 | 450 | {
|
|
472 | 472 | "cell_type": "markdown",
|
473 | 473 | "metadata": {},
|
474 | 474 | "source": [
|
475 |
| - "7. Print values of the six variables you assigned in \\#6. (Ex4–5)" |
| 475 | + "Q7. Print values of the six variables you assigned in \\#6. (Ex4–5)" |
476 | 476 | ]
|
477 | 477 | },
|
478 | 478 | {
|
|
505 | 505 | "cell_type": "markdown",
|
506 | 506 | "metadata": {},
|
507 | 507 | "source": [
|
508 |
| - "8. Print two strings in raw format (%r formatter) and two strings in general/string format (%s formatter) with formatting characters. (Ch6)" |
| 508 | + "Q8. Print two strings in raw format (%r formatter) and two strings in general/string format (%s formatter) with formatting characters. (Ch6)" |
509 | 509 | ]
|
510 | 510 | },
|
511 | 511 | {
|
|
538 | 538 | "cell_type": "markdown",
|
539 | 539 | "metadata": {},
|
540 | 540 | "source": [
|
541 |
| - "9. Concatenate two strings into a third string, then find the length of all three strings." |
| 541 | + "Q9. Concatenate two strings into a third string, then find the length of all three strings." |
542 | 542 | ]
|
543 | 543 | },
|
544 | 544 | {
|
|
575 | 575 | "cell_type": "markdown",
|
576 | 576 | "metadata": {},
|
577 | 577 | "source": [
|
578 |
| - "10. Print the three strings from \\#9 with a tab between the first and second and a newline between the second and third.\n" |
| 578 | + "Q10. Print the three strings from \\#9 with a tab between the first and second and a newline between the second and third." |
579 | 579 | ]
|
580 | 580 | },
|
581 | 581 | {
|
|
607 | 607 | "cell_type": "markdown",
|
608 | 608 | "metadata": {},
|
609 | 609 | "source": [
|
610 |
| - "11. Print the three strings from \\#9 with a stored formatter. (Ch7–8)" |
| 610 | + "Q11. Print the three strings from \\#9 with a stored formatter. (Ch7–8)" |
611 | 611 | ]
|
612 | 612 | },
|
613 | 613 | {
|
|
640 | 640 | "cell_type": "markdown",
|
641 | 641 | "metadata": {},
|
642 | 642 | "source": [
|
643 |
| - "12. Print a piece of text with five lines using both newline characters and a text block. (Ex9)" |
| 643 | + "Q12. Print a piece of text with five lines using both newline characters and a text block. (Ex9)" |
644 | 644 | ]
|
645 | 645 | },
|
646 | 646 | {
|
|
705 | 705 | "cell_type": "markdown",
|
706 | 706 | "metadata": {},
|
707 | 707 | "source": [
|
708 |
| - "13. Print a string containing a backslash, single-quote, double-qoute, newline, and tab. (Ex10)" |
| 708 | + "Q13. Print a string containing a backslash, single-quote, double-qoute, newline, and tab. (Ex10)" |
709 | 709 | ]
|
710 | 710 | },
|
711 | 711 | {
|
|
739 | 739 | "source": [
|
740 | 740 | "#### Answer to B. Taking input, reading and writing files, functions (Shaw Exercises 11-26) \n",
|
741 | 741 | "\n",
|
742 |
| - "1. Write some code, without using functions, that calculates the average of 5 numbers. Do it three different ways:\n", |
| 742 | + "Q1. Write some code, without using functions, that calculates the average of 5 numbers. Do it three different ways:\n", |
743 | 743 | "\n",
|
744 |
| - " - Write a .py file that takes input from the command line using `input()`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
745 |
| - " - Write a .py file that takes input from the command line using `argv`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
746 |
| - " - Enter code into two Jupyter notebooks cells: the first stores value as variables, and the second computes the average." |
| 744 | + "- Write a .py file that takes input from the command line using `input()`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
| 745 | + "- Write a .py file that takes input from the command line using `argv`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
| 746 | + "- Enter code into two Jupyter notebooks cells: the first stores value as variables, and the second computes the average." |
747 | 747 | ]
|
748 | 748 | },
|
749 | 749 | {
|
|
852 | 852 | "cell_type": "markdown",
|
853 | 853 | "metadata": {},
|
854 | 854 | "source": [
|
855 |
| - "2. Using functions, write some code that takes two strings, prints them with the first letter capitalized, prints them with all letters capitalized, prints the first and last letter of each, prints the length of each, and then prints the concatenation of the two strings. Do it two different ways:\n", |
| 855 | + "Q2. Using functions, write some code that takes two strings, prints them with the first letter capitalized, prints them with all letters capitalized, prints the first and last letter of each, prints the length of each, and then prints the concatenation of the two strings. Do it two different ways:\n", |
856 | 856 | "\n",
|
857 |
| - " - Write a .py file that uses `argv`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
858 |
| - " - In your Jupyter notebook, comment out the `argv` portions and hard code in the values of your strings. Then make sure the code runs the same." |
| 857 | + "- Write a .py file that uses `argv`. After the script works, paste the text of the file into your Jupyter notebook.\n", |
| 858 | + "- In your Jupyter notebook, comment out the `argv` portions and hard code in the values of your strings. Then make sure the code runs the same." |
859 | 859 | ]
|
860 | 860 | },
|
861 | 861 | {
|
|
931 | 931 | "cell_type": "markdown",
|
932 | 932 | "metadata": {},
|
933 | 933 | "source": [
|
934 |
| - "3. Using a text editor, create a comma-separated values (CSV) file with 5 columns and 5 rows. Save it in the same directory as your Jupyter notebook. In the Jupyter notebook, read and print the file in different ways, and write new files, as follows:\n", |
| 934 | + "Q3. Using a text editor, create a comma-separated values (CSV) file with 5 columns and 5 rows. Save it in the same directory as your Jupyter notebook. In the Jupyter notebook, read and print the file in different ways, and write new files, as follows:\n", |
935 | 935 | "\n",
|
936 |
| - " - Read your CSV file using `read()`, `readline()`, or `readlines()`, and print the output to the screen (`print()` command is optional in notebooks!).\n", |
937 |
| - " - Do the same but use a `with` block and a different one of `read()`, `readline()`, or `readlines()`.\n", |
938 |
| - " - Using either of the two above methods, then change one row of data, and write your data to a new CSV file.\n", |
939 |
| - " - Read your CSV file using Pandas and display the resulting DataFrame.\n", |
940 |
| - " - Save your DataFrame to a new file using Pandas." |
| 936 | + "- Read your CSV file using `read()`, `readline()`, or `readlines()`, and print the output to the screen (`print()` command is optional in notebooks!).\n", |
| 937 | + "- Do the same but use a `with` block and a different one of `read()`, `readline()`, or `readlines()`.\n", |
| 938 | + "- Using either of the two above methods, then change one row of data, and write your data to a new CSV file.\n", |
| 939 | + "- Read your CSV file using Pandas and display the resulting DataFrame.\n", |
| 940 | + "- Save your DataFrame to a new file using Pandas." |
941 | 941 | ]
|
942 | 942 | },
|
943 | 943 | {
|
|
1185 | 1185 | "name": "python",
|
1186 | 1186 | "nbconvert_exporter": "python",
|
1187 | 1187 | "pygments_lexer": "ipython3",
|
1188 |
| - "version": "3.7.0" |
| 1188 | + "version": "3.7.1" |
1189 | 1189 | }
|
1190 | 1190 | },
|
1191 | 1191 | "nbformat": 4,
|
|
0 commit comments