diff --git a/assets/screenshots/codespace-python-extension.png b/assets/screenshots/codespace-python-extension.png new file mode 100644 index 0000000..2049124 Binary files /dev/null and b/assets/screenshots/codespace-python-extension.png differ diff --git a/assets/screenshots/codespace-python-script.png b/assets/screenshots/codespace-python-script.png new file mode 100644 index 0000000..284dabf Binary files /dev/null and b/assets/screenshots/codespace-python-script.png differ diff --git a/source/ch-coding.ptx b/source/ch-coding.ptx index 08a988c..e41ed01 100644 --- a/source/ch-coding.ptx +++ b/source/ch-coding.ptx @@ -110,55 +110,118 @@ would like your Codespace to periodically run

-
- Python and Jupyter Notebooks +
+ Writing and Running Code

-Python is an -popular open-source all-purpose programming language, and -a convenient way to write, execute, and share the -results of Python code is a -Jupyter notebook. +Now that we've provisioned our Codespace virtual cloud computer, +we can use it to write and execute code using our web browser for +essentially any programming lanugage.

-To get started, create a Codespace -() -on either an existing or new repository -(). -You can then create a Jupyter notebook file named -notebook.ipynb. +Our first example will be Python, a popular general-purpose programming +language (and the same language we will use in +for Jupyter notebooks). In your Codespace, right-click on the file Explorer +to create a New File.... Name this file something.py so your +Codespace recognizes the file as a Python script (due to the .py file +extension). +This should trigger the prompt shown in +to install a Python extension - go ahead and do it. +

+
+ + +A screenshot of the prompt that displays in a Codespace +to install the Python extension. + + + Prompt to install the Python extension. +
+

+Add the line print("Hello world!") to your file. +A play icon () should be displayed +in the upper-right corner of the text editor (thanks to the +Python extension you installed). Clicking +this button should execute the code to print a greeting +as in . +

+
+ + +A screenshot of a Python script being executed within a Codespace. + + + Running a Python script in a Codespace. +
+

+Unless your Codespace has been customized via a +.devcontainer.json file (which we won't get +into here), you'll be using the default Codespace +image provided by GitHub. This environment is ready +to execute code from various standard programming +lanugages, though for something of them you may +need to run the script using the Terminal.

- -

-In a Codespace, any file with the extension *.ipynb -(short for IPYthon NoteBook, -Jupyter's original name) -will be treated as a -Jupyter notebook. When opening this file, you'll see a notebook -interface, and be prompted to -install the recommended 'Python' extension if it's -not already enabled - do this. -

-

-Then in your notebook file, click the Select Kernel -button, then Install/Enable suggested extensions for -Python+Jupyter. You should then have the option to select -a Python environment such as Python 3.*.*. -

-

-If successful, you should be able to enter -import sys; print(sys.version) into the displayed -text box, -and see the result of executing it with -Shift+Enter. -

-

-There are plenty of existing tutorials on the internet to help you -get acquainted with Python and Jupyter now that you have them -available to you in your Codespace. But to get you started, I've provided -one sample notebook -that you can upload to your Codespace to break the ice. +What do you think the programs in +, +, and + +will output? +Execute them in your Codespace to find out!

+ + + +# name this Python file something.py +# execute using the ▶ button or by running this in a terminal: +# python something.rb +a,b = 1,1 +print(a) +print(b) +for _ in range(10): + print(a+b) + a,b = b,a+b + + + Python code + + + + +# name this Ruby file something.rb +# execute by running this in a terminal: +# ruby something.rb +a,b = 1,1 +puts a +puts b +10.times do + puts a+b + a,b = b,a+b +end + + + Ruby code + + + + +// name this Javascript file something.js +// execute by running this in a terminal: +// node something.js +let a = 1, b = 1 +console.log(a) +console.log(b) +Array.from({ length: 10 }, _ => { + console.log(a+b) + let _a = a + a = b + b = _a + b +}) + + + + Javascript code +
Previewing GitHub Pages diff --git a/source/ch-jupyter.ptx b/source/ch-jupyter.ptx index ce238ba..03ce913 100644 --- a/source/ch-jupyter.ptx +++ b/source/ch-jupyter.ptx @@ -7,4 +7,55 @@ ...

+
+ Old jupyter stuff + +

+ Python is an + popular open-source all-purpose programming language, and + a convenient way to write, execute, and share the + results of Python code is a + Jupyter notebook. +

+

+ To get started, create a Codespace + () + on either an existing or new repository + (). + You can then create a Jupyter notebook file named + notebook.ipynb. +

+ +

+ In a Codespace, any file with the extension *.ipynb + (short for IPYthon NoteBook, + Jupyter's original name) + will be treated as a + Jupyter notebook. When opening this file, you'll see a notebook + interface, and be prompted to + install the recommended 'Python' extension if it's + not already enabled - do this. +

+

+ Then in your notebook file, click the Select Kernel + button, then Install/Enable suggested extensions for + Python+Jupyter. You should then have the option to select + a Python environment such as Python 3.*.*. +

+

+ If successful, you should be able to enter + import sys; print(sys.version) into the displayed + text box, + and see the result of executing it with + Shift+Enter. +

+
+

+ There are plenty of existing tutorials on the internet to help you + get acquainted with Python and Jupyter now that you have them + available to you in your Codespace. But to get you started, I've provided + one sample notebook + that you can upload to your Codespace to break the ice. +

+
\ No newline at end of file