Intro to
Computer
Science

Fall 2020
course
site
-->

Tools & "Hello World"

Your main focus this week should be in getting your software tools up and running, and running python programs.

There are a number of different ways to do this, in different environments on different operating systems. We'll explore several this semester.

The most easily accessible for this course is through jupyter.bennington.college , which provides a unix shell, a file editor, a python jupyter notebook. I've posted a video walking through them, and in the first assignment ask you to discuss your experiences in exploring them.

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.

The basics are :

You may well also want to install some of these tools on your own computer.

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!

command line vs GUI

(GUI is "Graphical User Interface" ... one of the many TLAs ("Three Letter Acronyms") that you'll run into in this class. ;)

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

Do you know what these words mean in a computing context?

We'll discuss in one of our zoom sessions; get your google-fu ready ...

random

If you've never seen xkcd before, now might be a good time to check out

xkcd's take on python .

an example

Chapter 1 in our textbook 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 x0 between 0 and 1: "))
    a = eval(input("Enter another number between 2.5 and 3.95: "))
    for i in range(10):
        x = a * x * (1 - x)
        print(x)

main()

Running it does things like this :

$ python chaos.py 
This program illustrates a chaotic function
Enter a number x0 between 0 and 1: 0.3
Enter another number between 2.5 and 3.95: 2.6
0.5459999999999999
0.6444984000000001
0.5957125522333439
0.6261816790969466
0.6086032780367155
0.6193338527991676
0.6129745220978772
0.6168155691275663
0.6145207193044473
0.6159010126099792
0.6150740837175518
0.6155706836670713
0.6152728843994869
0.6154516215177785
0.6153444000311806
0.6154087403917622
0.6153701388670858
0.6153933007502523
0.6153794039691007
0.6153877421633112

$ python chaos.py 
This program illustrates a chaotic function
Enter a number x0 between 0 and 1: 0.3
Enter another number between 2.5 and 3.95: 3.4
0.714
0.6942936000000001
0.7216499897967359
0.6829623588785634
0.736184235794212
0.6603378229918339
0.7625920605620139
0.6155543930813051
0.8046004196146782
0.5345431868599106
0.8459430120213084
0.44309967027432456
0.8389919984221719
0.4592870450195236
0.8443643480089761
0.44680486578919953
0.8403789441674028
0.45608339284944593
0.8434425274957054
0.4489605830450296

$ python chaos.py 
This program illustrates a chaotic function
Enter a number x0 between 0 and 1: 0.3
Enter another number between 2.5 and 3.95: 3.92
0.8231999999999999
0.5705236992000001
0.9605035187764999
0.1487111160422904
0.4962567904303676
0.9799450744579017
0.07703868397410887
0.27872660257093335
0.7880692876735773
0.654703055157012
0.886182501722339
0.3953832554248244
0.9370969200776104
0.23106942723797502
0.6964912803728457
0.8286534128107638
0.5565887822515238
0.9674470221152952
0.12345366354092743
0.42419439747706356

Do you see a pattern?

This function is the logistic map, and is a well known example of how chaotic behavior can come from a simple deterministic system.

Try it out for various values of x0 and a; See if you can describe its behavior.

For this class, we're more interested in the code than the math. This code has

... all of which we'll discuss soon.

https://cs.bennington.college /courses /fall2020 /introcs /notes /1b_tools
last modified Wed September 2 2020 2:13 pm