##

# Running Python on Your Computer

## Lesson Objectives

After this lesson, you will be able to…

- Write Python 3 scripts locally.
- Run Python 3 scripts via the command prompt.

## Defining Assumptions

We can’t use repl.it forever! We can run Python right on our computers.

- GA uses Macs for its default curriculum.
- We are happy to help you program Python on Windows or Linux as well.
- Sometimes you may need to ask questions about subtle differences!

Teaching Tips:

- Make sure students are aware that GA uses Macs as a default, but that you have directions for installing and can provide guidance on Linux and Windows as well.

## Let’s Get Installing!

This will take us 10 to 15 minutes, then we’ll regroup.

First, install Atom from https://atom.io/. This is where you’ll write your code.

Then, follow the Python 3 installation directions.

Teaching Tips:

- Students can use a different text editor if you or they prefer, but any reference to a text editor throughout this course is “Atom.”

- Point a link to where the directions are, or, if students downloaded them as a PDF, point out which PDF.

- You may have to cut off a student who is taking way too long to do this. It really isn’t fair to make everyone else wait in this case. Reassure the student that you will follow up with them during lunch or a break. Meanwhile, they should continue to use the website repl.it.

## Regroup

- You have Python 3 installed!
- You may have seen the in-line REPL (we’ll revisit!).
- You have a text editor — Atom — installed.
- You are ready to create a local `.py` file and run it.

Teaching Tips:

- Make sure everyone has either installed Python 3 or knows that it’s shelved until lunch.
- Make sure everyone has downloaded and can open the Atom text editor.

## In-Line REPL

Let’s check out a REPL.

- `Read-Evaluate-Print-Loop`.
- An interactive way to code.

Let’s do it!

- Open your terminal.
- Then, open your in-line REPL:

Mac/Linux:

    python

Windows:

    py

Teaching Tips:

- This seems simple, but go slowly.
- Some students might need `ipython`, not just `python`, or even `python3` — walk around and make sure they have it.

## We Do: Interactive Development

You can type any Python code you want here. Let’s declare a variable and do some math:

    x = 4
    y = 5
    print(x + y)

> Pro tip: `exit()` is the command for when you want to get out of this environment!

Teaching Tips:

- Have everyone practice this with you.
- Practice `exit` as well.
- Some students might need `exit`, not `exit()` — walk around and make sure they have it.

Talking Points:

- “You’re running Python locally!”

## We Do: Local Files

We can create a file with a `.py` extension — we can execute properly written Python code in a `.py` file.

1. Create a new file with a `.py` extension. Let’s call it `my_file.py`.
2. Open `my_file.py` in `Atom`.
3. In this file, declare some variables. Let’s mix integers and strings!

    favorite_tv_show = "Ninja Warrior"
    obstacles_cleared = 5
    time = "3 min, 20 sec"
    print("I cleared", obstacles_cleared, "on", favorite_tv_show, "in", time)

Save and close your file.

> Pro tip: Make sure you have a `print` statement.

Teaching Tips:

- Have everyone practice this with you. We want them to be able to run local code on their own.

## We Do: Running Local Files

Now we have code in a file, but we need to run it.

- Back on your terminal, we’ll navigate to where that file is located:

  - `cd` stands for “change directory” (“directory” is another word for “folder”).
  - `cd my_folder` changes to the directory `my_directory`.
  - `cd ..` goes up to the parent folder of the one you’re in.

- Running the file varies slightly between Windows and Mac/Linux:

  - Mac/Linux: `python my_file.py`
  - Windows: `py my_file.py`

Raise your hand if you need help!

Teaching Tips:

- Students have probably never seen a command line before this presentation. Show them how to do it, then walk around and make sure everyone is clear.

## Summary

- We now have Python 3 — the latest and greatest — installed.
- We can use our in-line REPL in the terminal.
- We can execute a local `.py` file with Python code in it.
- We know how to do this regardless of whether we use Mac, Linux, or Windows.

> Any questions?

Teaching Tips:

- If students seem a bit lost and there’s time, have them keep practicing this. Consider giving different tasks for them to perform in the REPL and the `.py`, and be clear about the difference between the two.

## Additional Resources

- Linux Command Line Cheat Sheet
- Mac Command Line Cheat Sheet
- Windows Command Line Cheat Sheet

Teaching Tips:

- Encourage students to go through these in their spare time if they’re curious.