-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
richelbilderbeek
committed
Jan 15, 2024
1 parent
231e3bd
commit 5bedfdb
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Working with Python scripts | ||
|
||
!!!- info "Learning objectives" | ||
|
||
* To be able to create a Python script | ||
* To be able to run a Python script | ||
|
||
???- question "For teachers" | ||
|
||
Teaching goals are: | ||
|
||
* Learners have created a Python script | ||
* Learners have run a Python script | ||
|
||
Lesson plan: | ||
|
||
* 5 mins: prior knowledge | ||
* 5 mins: presentation | ||
* 15 mins: challenge | ||
* 5 mins: feedback | ||
|
||
## Overview | ||
|
||
To run code, we use text files that are run as if each line | ||
was typed in into the Python interpreter. Such text files | ||
that run (interpreted) code are called 'scripts'. | ||
|
||
In this session, we create and run some simple Python scripts. | ||
|
||
## Exercises | ||
|
||
### Exercise 1: create a Python script | ||
|
||
- Learning goal: | ||
- to use a text editor in the terminal | ||
- to create, edit and save a file in the terminal | ||
- to create a trivial Python script to work on | ||
|
||
On Rackham, create a file called `hello_world.py`, | ||
using a text editor or Linux commands. | ||
The UPPMAX page on text editors is [here](http://docs.uppmax.uu.se/software/text_editors/). | ||
A free online book about the Linux can be found [here](https://linuxcommand.org/tlcl.php). | ||
|
||
!!! tip "Use the text editor 'GNU nano'" | ||
|
||
Copy-paste the following content into the script: | ||
|
||
``` | ||
print('Hello, world!') | ||
``` | ||
|
||
Save the script. | ||
Close the text editor. | ||
Verify that the script has its contents saved. | ||
|
||
### Exercise 2: run a Python script | ||
|
||
- Learning goal: to be able to run a Python script. | ||
|
||
Read the UPPMAX page on running a Python script, [here](http://docs.uppmax.uu.se/software/python/#running-python) | ||
|
||
Run the Python script you just created. | ||
|
||
### Exercise 3: | ||
|
||
- Learning goal: | ||
- repeat creating a Python script | ||
- to observe that an expression result is not shown on-screen by default | ||
|
||
Of the Python book [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html), | ||
go back to section 1.12 and do exercise 6. | ||
|
||
## Links | ||
|
||
* [How to Think Like a Computer Scientist: Learning with Python 3](https://openbookproject.net/thinkcs/python/english3e/index.html) |