Intro to
Programming
(with Python)

Fall 2019
course
site

Getting Started

Standard start of class : any questions so far?


Expectations : welcome to my classroom - Rob Jenkins, chronicle of higher ed

Basically, I expect you to act like responsible adults.

nuts'n'bolts

Nick (ncreel@marlboro.edu) is the CS tutor this term - stay tuned for details of where/when.

You can also email me (mahoney@marlboro.edu) with questions or setup times to work individually as needed.

The textbook is available at the bookstore, and there are other copies around (the library, Sci217 usually, friends, ...).

software tools

Your first task is to get to the point where you can write and run a python program on your computer. (Or, if you don't have a computer, on the lab computers. If so, please do check in with me.)

There are

It's common for people taking this course to have very different experience levels.

If getting up and running is easy for you, great. I encourage you to brush up on your current skills, and try to stretch a bit wherever you feel you need it.

Or if all this is brand new, that's OK: get help as needed, and plug away at getting all the pieces in place.

There are a number of ways to run python.

# From the command line interactively
$ python
>>>                       # You type something here, then hit "Enter".

# From the command line, running a file like "hello.py". 
# (You'll need to create the file first, and be in the correct folder.)
$ python hello.py
Hi!

# Using IDLE, the python.org's GUI IDE (acronyms!)
# application that will be installed when you get python from python.org.

# Within a Jupyter notebook in a browser, i.e. at jupyter.marlboro.college. 
# (Jim can give you a login there - ask if you want one.)

# In the cloud at pythontutor.com (for short-ish programs) visualizer.

# On a remote server like shannon.marlboro.college.
# (Jim can give you a login there - ask if you want one.)

Resources

Python has extensive online documentation, tutorials, and even browser consoles and editors where you can execute python in the cloud. See the resources page for lots of options.

The most important one is the official docs.

If you have a specific question or error, don't underestimate the power of just googling for what you want to know - often that will jump you to the right place in the documentation, or turn up someone else with that issue.

A First Program

Here's the "hello world" program in python :

 # This file is hello.py - a first short program in python.
 print("Hello world")

From a terminal program (the $ is the prompt waiting for you to type), in the same folder as the file (see below for more)

$ python hello.py
Hello world!

You should have this working this week. Again - you need help, ask, don't wait and get behind.

command line vs GUI

A bit more on the command line ... see In the Beginning was the Command Line

Mac/Unix:
# Mac: The application is /Applications/Utilities/Terminal
# Unix: depends; look for "Terminal" in application menu
$ cd /folder/name        # change directory
$ ls                     # list directory
$ pwd                    # print working directory 
$ python file.py         # run python program in file.py

Windows
# XP: Start ... Programs ... Accessories ... Command Prompt
> cd \folder\name        # change directory
> dir                    # list directory
> cd                     # show current directory
> python file.py         # run python program in file.py

running python

And a bit more on running python.

In general, programming can be done with text editors and the command line (which is the "old school" way I'll be showing you) or with an IDE (Integrated Development Environment). Some people swear by IDEs. My opinion is that they hide the details of what's going on, and when you're starting out (like in this class), it's good to understand those details.

The difference between an editor and an IDE is essentially how much can be done from within the application to compile, run, debug etc the program. Or in larger settings, the programming project. If you think you'd rather try an IDE, the list at http://wiki.python.org/moin/PythonEditors may be helpful.

Do make sure you know what folder you're in while you're working with a python file or at the command prompt. If nothing is working, there's a good chance that you're just in the wrong folder.

overview of computers and terminology

random

xkcd...

an example

Chapter 1 uses a chaos program as a first example.

# File: chaos.py
# A simple program illustrating chaotic behavior.

def main():
    print("This program illustrates a chaotic function")
    x = eval(input("Enter a number between 0 and 1: "))
    for i in range(10):
        x = 3.9 * x * (1 - x)
        print(x)

main()

We'll run this in class and discuss.

I also have a Jupyter notebook with graphical output from this example in the code/chaos_notebook folder.

https://cs.marlboro.college /cours /fall2019 /python /notes /chap1
last modified Tue December 3 2024 5:34 pm