Lab 1: Hello Pythonic World

The first thing you should do is take this survey to help us pair you for future labs: Partner Coding Survey. If you have a chosen partner then make them your preference. If there is someone you don't want to work with share that info too.

Overview

In today's lab we're going to boss some computers around in several different ways. Two different online platforms, from a file, from an interactive shell, loaded from a github repository, and on a local machine.

Here is our first program:

      
        print("Hello world"*10)
      
    

The many ways to run a python program

Python is a programming language which allows you to do almost anything. Process millions of operations, create fun games, make trades on the stock markets, scrape the internet for cool stuff, model math problems, and so in that order.

What I want you to learn from today is that a "program" is a set of instructions that a computer can follow. If you want to write your own program then you need to know how to have a computer execute your instructions. You might call this "running a program". I will give you several ways to have some code you write executed by a machine. (That is an amazing thing in the grand scope of human existence, btw.)

The following methods of running a python program will be handy for our class:

Cloud9

Cloud9 is an online "virtual machine" which gives you your own personal web server to hack at. I will use it often in our class for many reasons:

Working with cloud9

If you have already created a cloud9 account then head there now and create a new "custom" workspace. If you have not made a cloud9 account then I suggest you first make a GitHub account, and then a cloud9 account from your GitHub account.

Once you have made a workspace you will see this:

What a c9 workspace looks like, roughly

The left panel is a file browser, which has files in your workspace. The main pane (empty in my photo) is a text editing area. The bottom panel has a "terminal" or "command-line" where you can execute code.

Running python version 1

From the "terminal" (the bash tab of the bottom pane) type python3. You should see something like this:

The Python Terminal/Shell

Now type into the terminal our program (print("Hello world"*10)) then hit enter.

Congratulations you have run a python "program"!

Hooray!

Let's exit python by typing exit() and hitting enter.

Running python version 2

Create a text file and call it hello.py.

Open the file for editing.

Insert our program (print("Hello world"*10)).

Save the file.

From the terminal type ls. (This is a unix command which lists the files in your current directory.) You should see hello.py listed.

Type python3 hello.py and hit enter.

You did it again you sly dog you!

Save the URL of your cloud9 workspace so that you can send it with your lab submission.

repl.it

A faster but less permanent way to run code is repl.it. REPL stands for read eval print loop, and it's a hip way to refer to interactive coding.

In class if you want to try something very quickly repl.it is a good way, even from a phone. (although coding on a phone is awful, you probably only want to print("hi"). Know what I'm sayin'?).

Head to repl.it, and execute our print statement once from the right side of the screen (the python "shell")

Now put the line into the text file on the left side of the screen and "run" it.

If you want to make a repl.it account feel free.

Save your file (it will make a unique URL for your work).

Save the URL of your repl.it file for your lab submission.

Using GitHub with Cloud9

Our class has been selected by GitHub for super cool status. They have granted us an organization with private repositories. None of that matters to you right now, so it's cool.

GitHub is a way for coders to share code, protect themselves from stupid mistakes, steal ideas, and market themselves. Our github organization is http://github.com/cisc106.

I have created a "repository" called: hello-world. We will copy this "repository" and start hacking at it.

Go to your cloud9 dashboard and create a new workspace, but put https://github.com/cisc106/hello-world in the appropriate space (be careful, if you click a different type of app it will erase the repository input field).

Once your workspace is created you'll see that you have a hello.py file already!

What you've done is even stronger than that, but for now, just run the program like we did above.

You have now "cloned" a git repository and run it! Ask me tomorrow about how cool that is.

For your submission save the URL of this cloud9 workspace.

Your own machine

You can install python on pretty much any machine. The installation process is different from platform to platform but you'll find a way by google searching install python3 and using common sense.

In this lab your computer probably already has python.

Run our hello world program through that machine.

Submitting your work

For today I want you to compose an email to your personal py.prof.ninja email address as laid out in our submission guideline (small in-class projects). Zhong will give you the message title.

Your message should have the following four things:

  1. The URL address of your cloud9 workspace where you were able to run "hello world"
  2. The URL address of a repl.it file with your name (commented) and a statement which prints "hello world".
  3. Your github account name.
  4. The URL of your git cloned workspace.
  5. Promise me that you ran the program once on your local machine, and will run the program on your home machine before class tomorrow.