Skip to content

Commit

Permalink
'Working with Python scripts' ready
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Jan 15, 2024
1 parent 231e3bd commit 5bedfdb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/morning_session/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This module introduces the fundamentals of Python programming language.
|---------------|-------------------------------|
| 09:00-10:00 | [Using the Python interpreter](using_the_python_interpreter.md) [The way of the program](the_way_of_the_program.md) |
| 10:00-10:15 | Break |
| 10:15-11:00 | Using a Python script, variables|
| 10:15-11:00 | [Working with Python scripts](working_with_python_scripts.md), variables|
| 11:00-11:15 | Break |
| 11:15-12:00 | Exercises |
| 13:00-14:00 | Functions and Modules |
Expand Down
75 changes: 75 additions & 0 deletions docs/morning_session/working_with_python_scripts.md
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)

0 comments on commit 5bedfdb

Please sign in to comment.