Commit 665dbfe4 by Arucas Chacon

### First commit

parents
\n", "Variables defined in one cell exist in all other cells once executed, so the relative location of cells in the notebook does\n", "not matter (i.e., cells lower down can still affect those above). Remember: Notebook cells are just a way to organize a program: as far as Python is concerned, all of the source code is one long set of instructions.\n", "
\n", "
\n", "

Exercise - Swapping Values

\n", "
\n", "
\n", " Fill the table showing the values of the variables in this program after each statement is executed.\n", "
\n", "
" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "# Command # Value of x # Value of y # Value of swap #\n", "x = 1.0 # # # #\n", "y = 3.0 # # # #\n", "swap = x # # # #\n", "x = y # # # #\n", "y = swap # # # #" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise - Predicting Values

\n", "
\n", "
\n", "What is the final value of position in the program below? (Try to predict the value without running the program, then check your prediction.)\n", "\n", "
\n", "
" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "initial = \"left\"\n", "position = initial\n", "initial = \"right\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise - Choosing a name

\n", "
\n", "
\n", "Which is a better variable name, m, min, or minutes? Why? Hint: think about which code you would rather inherit from someone who is leaving the lab:\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "ts = m * 60 + s\n", "tot_sec = min * 60 + sec\n", "total_seconds = minutes * 60 + seconds" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Key Points

\n", "
\n", "
\n", "
\n", "
• Use variables to store values.
• \n", "
• Use print to display values.
• \n", "
• Variables persist between cells.
• \n", "
• Variables must be created before they are used.
• \n", "
• Variables can be used in calculations.
• \n", "
• Use an index to get a single character from a string.
• \n", "
• Use a slice to get a substring.
• \n", "
• Use the built-in function len to find the length of a string.
• \n", "
• Python is case-sensitive.
• \n", "
• Use meaningful variable names.
• \n", "
\n", "
\n", "
" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }

6.52 KB

6.46 KB

163 KB

5.88 KB

9 KB

5.86 KB

4.38 KB

42.6 KB

12.2 KB

89.6 KB

images/numpy.png 0 → 100644

15.7 KB

75.2 KB

 \ No newline at end of file

33.2 KB

159 KB

1.41 KB

75.7 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!