Skip to content

Commit

Permalink
Merge pull request #31 from RENCI-NRIG/escott
Browse files Browse the repository at this point in the history
fixes typos in PE100-02 and bad import in PE101-02NumPy
  • Loading branch information
erikscott authored May 22, 2024
2 parents c44d69e + 908bf48 commit 3ecd396
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 95 deletions.
57 changes: 49 additions & 8 deletions theme1/PE100/PE100-02TypesVarsAndOperators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9be5ce2d-e475-442c-bcdd-1ebe1668cf6b",
"id": "bdf177e9-7e0c-4772-a8ef-f93869a1f5bf",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -533,7 +533,35 @@
"id": "f8ff396b-d067-485c-8c0a-f9069991d2dd",
"metadata": {},
"source": [
"# TODO - type coercion"
"How do we handle situations like that, where `second_thing` held a string representing a seven, but because it was a string variable it couldn't be used as an integer? Python provides a few functions to convert values from one type to another. The `str()` function takes a variable and converts it to a string. The `float()` and `int()` functions convert their arguments to floating-point and to integer numbers, respectively."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8b0fa20d-3cf4-4e9d-9c66-28619c8598b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\n",
"13.0\n"
]
}
],
"source": [
"print(first_thing + int(second_thing))\n",
"print(first_thing + float(second_thing))"
]
},
{
"cell_type": "markdown",
"id": "8fc293e2-f0f6-4b3c-a9ed-f34c07a5f905",
"metadata": {},
"source": [
"Sometimes the expressions we need to evaluate can be very long. It would be nice if we could split up a long expression and spread it out over a few lines. As a small example, we'll take a look at 4+2+3. Manyb programming languages will let us just split an expression anywhere we want, such as:"
]
},
{
Expand All @@ -552,15 +580,26 @@
"id": "9552bdf3-e316-4151-859e-2428672a4e9d",
"metadata": {},
"source": [
"That isn't right. The last line, ```+3```, was evaluated and printed as the result of running that cell. It turns out, if we need to continue an expression on the next line, we just end the line with a backslash ```\\``` and press enter. It has to be a backslash, by the way, and **cannot** be the forward slash like we use for division."
"...but that result isn't right. The last line, `+3`, was evaluated and printed as the result of running that cell. In Python,it turns out, if we need to continue an expression on the next line we just end the current line with a backslash `\\` and press enter. It has to be a backslash, by the way, and **cannot** be the forward slash like we use for division."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "a3f81522-1f91-4fc5-92d8-02d8d88d208f",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4+2\\\n",
"+3"
Expand Down Expand Up @@ -627,7 +666,7 @@
"id": "413f8e00-ffb5-4304-820f-80fd214ac8dc",
"metadata": {},
"source": [
"Some, probably most, languages contain strings inside \"double quotes\", ```\"```, which is shift+apostrophe on US English keyboards. Other languages (SQL and Pascal are the only two I can think of) use single quotes: ```'```. Python let's you use either one. You *do* have to be consistent in each string, but it can vary from one string to the next:"
"Some, probably most, languages contain strings inside \"double quotes\", ```\"```, which is shift+apostrophe on US English keyboards. Other languages (SQL and Pascal are the only two I can think of) use single quotes: ```'```. Python lets you use either one. You *do* have to be consistent in each string, but it can vary from one string to the next:"
]
},
{
Expand Down Expand Up @@ -706,9 +745,11 @@
"That sentence contains three things, inside the string itself:\n",
"1. Double Quotes to surround a direct quotation\n",
"2. A single quote, also called an apostrophe depending on how it's used, to make a contraction, and\n",
"3. A totally not incredibly awesome/terrifying molecule you have to google to believe.\n",
"3. A totally awesome/terrifying molecule you have to google to believe.\n",
"\n",
"OK, I'll save you the trouble. [Prepare to lose most of a day's productivity](https://www.science.org/content/blog-post/things-i-won-t-work-hexanitrohexaazaisowurtzitane). You're welcome.\n",
"\n",
"OK, I'll save you the trouble. [Prepare to lose most of a day's productivity](https://www.science.org/content/blog-post/things-i-won-t-work-hexanitrohexaazaisowurtzitane). You're welcome."
"(Derek has written gobs of articles on fun substances. [Here are some more.](https://www.science.org/topic/blog-category/things-i-wont-work-with) )"
]
},
{
Expand Down
39 changes: 38 additions & 1 deletion theme1/PE101/python-packages-conda.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,44 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Using Python packages & libraries, Conda"
"# PE101-01: Using Python Packages and Libraries\n",
"\n",
"By itself, Python provides everything you need to write programs. These programs won't have a fancy user interface and they may not run very fast, but they'll work. If that's all Python offered, it might have become a popular language but it wouldn't have taken over most of the world the way it has. No, what Python has going for it is a simple way to take commonly-used chunks of code, wrap them up neatly into sharable budles, and distribute those bundles far and wide. The mechanism for doing this in Python is called **packages**.\n",
"\n",
"In this training unit, PE101-01, we're going to look at some of the packages that come with Python. These are packages that you can count on being available anywhere you can run Python. In the next unit, PE101-02, we'll look at how to find and use packages hosted in _repositories_ available to anyone but not necessarily already installed where you're running your programs.\n",
"\n",
"Python is, by itself, a rather simple language. The PE100 series of units has introduced you to almost all of the language. The language is kept small by moving the \"nice to have, but not really necessary\" parts into their own independent packages. Let's start with an example:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pi equals 3.141592653589793\n",
"There are 2652 possible outcomes when drawing two cards from a deck\n",
"The natural logarithm of 7.994 is 2.0786912602891316\n"
]
}
],
"source": [
"import math\n",
"\n",
"print(\"pi equals\", math.pi)\n",
"print(\"There are\", math.perm(52,2), \"possible outcomes when drawing two cards from a deck\")\n",
"print(\"The natural logarithm of 7.994 is\", math.log(7.994))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are literally oodles of mathematical functions already implemented for you in the `math` package. To see a list of them as they stand currently, see [math - mathematical functions](https://docs.python.org/3/library/math.html) in the current Python documentation.\n",
"\n"
]
}
],
Expand Down
Loading

0 comments on commit 3ecd396

Please sign in to comment.