From d395e28aedab457bc59ac40fbb355fb37a6db245 Mon Sep 17 00:00:00 2001
From: pelibby16 <pelibby16@earlham.edu>
Date: Thu, 17 Oct 2024 16:18:14 -0400
Subject: [PATCH] add to python module

---
 topical-units/env-python/BASICS.md  | 100 ++++++++++++++++++++++++++++
 topical-units/env-python/JUPYTER.md |  28 ++++++++
 topical-units/env-python/README.md  |  30 ++++++++-
 3 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 topical-units/env-python/BASICS.md
 create mode 100644 topical-units/env-python/JUPYTER.md

diff --git a/topical-units/env-python/BASICS.md b/topical-units/env-python/BASICS.md
new file mode 100644
index 0000000..9d5b35d
--- /dev/null
+++ b/topical-units/env-python/BASICS.md
@@ -0,0 +1,100 @@
+# Basic Python Examples
+
+## Comments
+```py
+print("test one")
+# This is a comment that will not affect the code around it
+print("test two")
+print("test three")     # Comments can also be on the end of a line
+#print("test four")
+```
+"test four" will not be printed, since that line is commented out. 
+
+## Math
+```py
+print(5 + 7)        # prints 12 (5 plus 7)
+print(7 - 5)        # prints 2 (7 minus 5)
+print(1 / 4)        # prints 0.25 (1 divided by 4)
+print(3 * 5)        # prints 15 (3 times 5)
+print(3 ** 2)       # prints 9 (3 squared)
+print(10 // 3)      # prints 3 (10 divided by 3, rounded down)
+print(10 % 3)       # prints 1 (remainder of 10 divided by 3)
+```
+Python uses a lot of typical mathematical symbols, and some that are less common. A lot more mathematical operations, such as cosine and log, can be used as well, but are included as functions instead of just symbols.
+
+
+## Functions
+```py
+def myFunction():   # Defines a function called "myFunction"
+    print("The function has been run")
+    print("Anytime myFunction() is run, this text will print")
+
+myFunction()        # Run the function
+```
+A function is a way to package and reuse a piece of code. In the above example, `myFunction` contains a few lines of code. Python uses indentation to show that the two print statements are a part of the function. Any time `myFunction()` is run, python will run all code contained within the function.
+
+## Variables
+```py
+myInteger = 1234
+myFloat = 12.34
+myString = "This is also a variable"
+myArray = [1,2,3,4,5]
+myBoolean = True
+```
+Variables allow us to store data and give it a name that can be referenced later. The stored information can be a number, a string, or a list of values (called an array). 
+
+## If statements
+```py
+# Example 1
+if myBoolean == True:
+    print("It's true!")
+else:
+    print("It's false!")
+
+# Example 2
+if myInteger == 0:
+    print("It's zero!")
+else if myInteger == 1:
+    print("It's one!")
+else:
+    print("It's not one or zero!")
+```
+If statements are important for selecting different options based on condition. In example 1, the condition is a boolean 
+
+
+## While Loops
+```py
+while myInteger < 10:
+    print(myInteger)
+    myInteger = myInteger + 1
+```
+
+## For loops
+```py
+# Example 1
+for x in [1,2,3,4]:
+    print(x)        # prints numbers from 1 to 4, one at a time.
+
+# Example 2
+for x in range(10):
+    print(x)        # prints numbers from 0 to 9, one at a time.
+
+# Example 3
+for x in "string of text":
+    print(x)
+
+```
+For loops are used to iterate over several pieces of information. Frequently, this takes the form of an array. In example 1, we are iterating over each piece of data in the array `[1,2,3,4]`. The statements inside the for loop will be run once for each iteration. The first time, "1" will be printed, the second time "2" will be printed, and so on.
+
+In the second example, the `range()` function is used. This tells the for loop to iterate over a range of numbers from 0 to N (not inclusive).
+
+The third example demonstrates iterating over letters in a string. The string is used as though it is an array of single letters. The first iteration will print "s", the second will print "t", and so on.
+
+## Working with Files
+```py
+with open('test.txt', 'r') as file:     # open a file called "test.txt"
+    for line in file:                   # iterate over each line in file
+        print(line)
+```
+This example shows how to open a file using a `with` statement. The with statement simplifies this process by handling the opening and closing of the file. Contents of the file will be available to any code written in the indented block under the with statement, in this case, a for loop.
+
diff --git a/topical-units/env-python/JUPYTER.md b/topical-units/env-python/JUPYTER.md
new file mode 100644
index 0000000..cbab4d2
--- /dev/null
+++ b/topical-units/env-python/JUPYTER.md
@@ -0,0 +1,28 @@
+# Using Jupyter / Jupyterhub
+This page will guide you through the process of getting started with Jupyterhub, which we host here on campus for students to use for programming in Python and other languages.
+
+## Access
+Navigate to [juypter.cs.earlham.edu](https://jupyter.cs.earlham.edu) in a browser, and log in with your CS credentials (these are separate from your Earlham credentials that you use to log into Zimbra or Moodle). If you don't have a username/password for CS, get in touch with your instructor, or email admin@cs.earlham.edu so that we can set one up for you.
+
+Once you log in, you should see a drop-down menu with options. You can use the default profile: `2GB RAM, 0.5 Core (CS128)`. Click `Start`. After it loads for a bit, you should be able to start programming.
+
+## Using the Jupyterlab interface
+Jupyter has a very nice page with a lot of details about the interface [HERE](https://jupyterlab.readthedocs.io/en/4.1.x/user/interface.html), if you'd like more information.
+
+A quick synopsis of the lab:
+- `File Browser` (Left edge of the screen): This works a lot like the filebrowser on your computer. You can use it to create new files and folders, organize, delete, and rename. This filebrowser includes only remote files that you are storing on the CS server, and does not access or use the local files on your laptop.
+- `Main Work Area` (Right side of the screen): The majority of the screen is taken up by the work area, which is where you'll be editing code and files. It should start out by displaying a "Launcher", which gives you options for several different versions of Python, as well as some other languages.
+
+
+## Running Python Code
+Start by selecting "Python 3.12" from the launcher. This will start a new, blank Notebook in the work area. Try typing `print("Hello World!")` in the notebook, and clicking the little "play" button at the top of the Notebook (you can also use `shift`+`enter` to run your current cell)
+
+When you run the "Cell", it should look something like this:
+```
+[1]: print("Hello World!")
+```
+`Hello World!`
+
+Each "Cell" can contain python code, and when it is run, the entire cell will be run all at once. Any output from the code in that cell will be put below it (in between the current cell and the next). Mutiple cells can be used to space out your code, and add space for output from your code. Looking at a large amount of code can be much easier when it is divided up into chunks. The number to the left of each cell represents the order that they have been run in. Notice that re-running your cell will increment the number each time.
+
+You can also use Jupyter to write and edit a normal `.py` file, which python code outside of a notebook. All the same code will work in a `.py` file, just without the added interactive elements of the notebook environment.
\ No newline at end of file
diff --git a/topical-units/env-python/README.md b/topical-units/env-python/README.md
index 9a9c604..1104e7e 100644
--- a/topical-units/env-python/README.md
+++ b/topical-units/env-python/README.md
@@ -1,4 +1,30 @@
 # <img width=30px height=30px style='margin-right: 10px; margin-bottom: -3px;' src="https://seeklogo.com/images/P/python-logo-A32636CAA3-seeklogo.com.png"> Python Topical Unit (Under Construction)
-## (not applicable if you have taken CS128 at Earlham)
-Python is a widely-used, interpreted, object-oriented, high level programming language. It is very popular, particularly among domain scientists such as biologists. This language unit is designed for people that have not yet taken CS128 at Earlham.
+**Note: This module is not applicable if you have taken CS128 at Earlham**
 
+Python is a widely-used, interpreted, object-oriented, high level programming language. It is very popular, particularly among domain scientists such as biologists. This language unit is designed for people that have not taken CS128 at Earlham. If you are in a major other than CS, or have previous programming experience in a language other than Python, this module might be perfect for you.
+
+## Resources (and additional READMEs)
+- [Using Jupyterhub README](JUPYTER.md)
+- [Python Basics README](BASICS.md)
+- [Codingbat Python Practice](https://codingbat.com/python)
+- Using a terminal (Running python option 1)
+
+## Learning Goals
+- Basic understanding of python assuming a very light programming background, or none at all.
+  - Folks outside CS (Physics, Math, Chem, Bio).
+  - This + AP can replace CS128.
+
+## Deliverables
+- Write a helloWorld script in python. It should contain a single function called `helloWorld()` that prints the string "Hello World!".
+
+
+
+
+
+## Notes / Ideas
+- Using a notebook (ipynb)
+  - jupyter.cs.earlham.edu
+  - should prep for the data analysis module
+  - lab 1-4 of 128
+- Using python on the command line (py)
+  - short introduction. Start by pasting code from a notebook into a .py file
\ No newline at end of file
-- 
GitLab