|
13 | 13 | "source": [ |
14 | 14 | "## Values and Types\n", |
15 | 15 | "Values are basic things a program works with. Values come in several different types:\n", |
16 | | - "* string: Is any value between quotes ('' or \"\") ex. 'Hello Coding Circle', \"I am very smart\", \"342\"\n", |
17 | | - "* integer: Is any whole number, positive or negitive ex. 145, -3, 5\n", |
18 | | - "* float: Is any number with a decimal point ex. 3.14, -2.5 \n", |
| 16 | + "* A string is any value between quotes ('' or \"\") e.g. 'Hello Coding Circle', \"I am very smart\", \"342\"\n", |
| 17 | + "* An integer is any whole number, positive or negative e.g. 145, -3, 5\n", |
| 18 | + "* A float is any number with a decimal point e.g. 3.14, -2.5 \n", |
19 | 19 | "\n", |
20 | 20 | "To tell what type a value is, use the built-in function 'type()'" |
21 | 21 | ] |
|
59 | 59 | "source": [ |
60 | 60 | "To print a value to the screen, we use the command 'print'\n", |
61 | 61 | "\n", |
62 | | - "ex. print 1" |
| 62 | + "e.g. print 1" |
63 | 63 | ] |
64 | 64 | }, |
65 | 65 | { |
|
93 | 93 | ] |
94 | 94 | }, |
95 | 95 | { |
96 | | - "cell_type": "code", |
97 | | - "execution_count": null, |
98 | | - "metadata": { |
99 | | - "collapsed": true |
100 | | - }, |
101 | | - "outputs": [], |
| 96 | + "cell_type": "markdown", |
| 97 | + "metadata": {}, |
102 | 98 | "source": [ |
103 | 99 | "## Variables\n", |
104 | | - "A variable is a name that you give a value. You can then use this name anywhere you would use the value that the name refers to.\n", |
| 100 | + "A variable is a name that you give a value. You can then use this name anywhere you would use the value that the name refers to. \n", |
105 | 101 | "\n", |
106 | | - "The name has some rules, it must only contain letters, numbers, and/or the underscore character ('\\_'). _(That looks like a face...)_ It also cannot start with a number. It can start with an underscore but this usually means something special, so stick to letters for now.\n", |
| 102 | + "It has some rules.\n", |
| 103 | + "* It must only contain letters, numbers and/or the underscore character. \n", |
| 104 | + "* However, it cannot start with a number.\n", |
| 105 | + "* It can start with an underscore but this usually means something special so stick to letters for now. \n", |
107 | 106 | "\n", |
108 | | - "To assign a variable you use the assignment operator: '=' ex. my_name = 'Charlotte'" |
| 107 | + "To assign a value to a variable, you use the assignment operator: '=' e.g., my_name = 'Charlotte'" |
109 | 108 | ] |
110 | 109 | }, |
111 | 110 | { |
|
125 | 124 | "cell_type": "markdown", |
126 | 125 | "metadata": {}, |
127 | 126 | "source": [ |
128 | | - "Notice that when you ran that, nothing printed out. To print a variable, you use the same statement you would use to print the value. ex print WHALE" |
| 127 | + "Notice that when you ran that, nothing printed out. To print a variable, you use the same statement you would use to print the value. e.g. print WHALE" |
129 | 128 | ] |
130 | 129 | }, |
131 | 130 | { |
|
144 | 143 | "metadata": {}, |
145 | 144 | "source": [ |
146 | 145 | "### TRY IT\n", |
147 | | - "assign the name of a sea creature to the variable sea_creature. Then print the value" |
| 146 | + "Assign the name of a sea creature to the variable sea_creature. Then print the value." |
148 | 147 | ] |
149 | 148 | }, |
150 | 149 | { |
|
154 | 153 | "collapsed": false |
155 | 154 | }, |
156 | 155 | "outputs": [], |
157 | | - "source": [] |
| 156 | + "source": [ |
| 157 | + "sea_creature = 'orca'\n", |
| 158 | + "print sea_creature" |
| 159 | + ] |
158 | 160 | }, |
159 | 161 | { |
160 | 162 | "cell_type": "markdown", |
161 | 163 | "metadata": {}, |
162 | 164 | "source": [ |
163 | | - "*Reccomendation* try to name your variables with descriptive names. Naming a variable 'a' seems easy to type, but won't help you figure out what it is doing when you come back to your code six months later." |
| 165 | + "*Reccomendation* \n", |
| 166 | + "Name your variables with descriptive names. Naming a variable 'a' is easy to type but won't help you figure out what it is doing when you come back to your code six months later." |
164 | 167 | ] |
165 | 168 | }, |
166 | 169 | { |
|
201 | 204 | }, |
202 | 205 | "outputs": [], |
203 | 206 | "source": [ |
| 207 | + "apples = 15\n", |
204 | 208 | "apples_left = 15 - 3\n", |
205 | 209 | "print apples_left" |
206 | 210 | ] |
|
301 | 305 | "source": [ |
302 | 306 | "## Order of operations\n", |
303 | 307 | "\n", |
304 | | - "You can combine many operators in a single python statement. The way python evaluates it is the same way you were taught to in elementary school. PEMDAS for Please Excuse My Dear Aunt Sally. Or 1. Parenthesis, 2. Exponents, 3. Multiplication, 4. Division, 5. Addition, 6. Subtraction. Left to right, with that precedence. It is good practice to always include parenthesis to make your intention clear, even if order of operations is on your side." |
| 308 | + "You can combine many operators in a single python statement. The way python evaluates it is the same way you were taught to in elementary school. PEMDAS for Please Excuse My Dear Aunt Sally. Or 1. Parentheses, 2. Exponents, 3. Multiplication, 4. Division, 5. Addition, 6. Subtraction. Left to right, with that precedence. It is good practice to always include parentheses to make your intention clear, even if order of operations is on your side." |
305 | 309 | ] |
306 | 310 | }, |
307 | 311 | { |
|
332 | 336 | "source": [ |
333 | 337 | "## Modulus operator\n", |
334 | 338 | "\n", |
335 | | - "The modulus operator is not one you were taught in school. It returns the remainder of integer division. It is useful in a few specific cases, but you can go months without using it." |
| 339 | + "The modulus operator is not one you were taught in school. It returns the remainder of integer division. It is useful in a few specific cases, but you could go months without using it." |
336 | 340 | ] |
337 | 341 | }, |
338 | 342 | { |
|
436 | 440 | "source": [ |
437 | 441 | "## Asking the user for input\n", |
438 | 442 | "\n", |
439 | | - "To get an input for the user we use the command raw_input() and assign it to a variable\n", |
| 443 | + "To get an input for the user we use the built-in function raw_input() and assign it to a variable.\n", |
440 | 444 | "\n", |
441 | | - "The result is always a string" |
| 445 | + "NOTE: The result is always a string." |
442 | 446 | ] |
443 | 447 | }, |
444 | 448 | { |
|
457 | 461 | "cell_type": "markdown", |
458 | 462 | "metadata": {}, |
459 | 463 | "source": [ |
460 | | - "You can pass a string to the raw_input() command to prompt the user with what you are looking for.\n", |
| 464 | + "You can pass a string to the raw_input() function to prompt the user for what you are looking for.\n", |
461 | 465 | "\n", |
462 | | - "ex. raw_input('How are you feeling?')\n", |
| 466 | + "e.g. raw_input('How are you feeling?')\n", |
463 | 467 | "\n", |
464 | 468 | "Hint, add a new line character \"\\n\" to the end of the prompt to make the user enter it on a new line." |
465 | 469 | ] |
|
482 | 486 | "source": [ |
483 | 487 | "If you want the user to enter a number, you will have to convert the string. Here are the conversion commands.\n", |
484 | 488 | "\n", |
485 | | - "* To convert a variable to an integer, use int, e.g., int(variable_name)\n", |
486 | | - "* To convert a variable to a float, use float e.g., float(variable_name)\n", |
487 | | - "* To convert a variable to a string, use str e.g., str(variable_name)" |
| 489 | + "* To convert a variable to an integer, use int -- e.g., int(variable_name)\n", |
| 490 | + "* To convert a variable to a float, use float -- e.g., float(variable_name)\n", |
| 491 | + "* To convert a variable to a string, use str -- e.g., str(variable_name)" |
488 | 492 | ] |
489 | 493 | }, |
490 | 494 | { |
|
505 | 509 | "metadata": {}, |
506 | 510 | "source": [ |
507 | 511 | "### TRY IT\n", |
508 | | - "Prompt the user for their favorite color and store the result in a variable called color" |
| 512 | + "Prompt the user for their favorite color and store the value in a variable called color." |
509 | 513 | ] |
510 | 514 | }, |
511 | 515 | { |
|
0 commit comments