Session 2

An Introduction to Programs


CS 1510
Introduction to Computing


An Opening Challenge

... is in the file seconds_left.py. Write a simple arithmetic expression of the sort you saw in yesterday's lab.



The Scope of the Course

I received many interesting questions in response to last session's e-mail homework. You asked questions across the full range of CS, from programs to applications to hardware. Strictly speaking, many of them did not meet the terms of the assignment... Even so, I am glad you are curious about computers and the world!

I will respond to these questions by e-mail as time permits. If you are so curious you can't wait, feel free to ask me again sometime.

The scope of this course does not allow us to cover all the ideas in your questions. CS 1510 aims to start you on the path of thinking like a computer scientist. We will think a lot about different kinds of problems and how to solve them by representing and manipulating data. Occasionally, we will discuss lower-level ideas, too.

This course prepares you for many other courses, in which you will explore computing in a broader and deeper way. In those courses, you will learn the secrets to many of your questions.



What is a Program?

Your textbook begins with much discussion of computer science and computer programming, but it passes by the definition of program rather quickly, on Page 10. It does elevate the definition to the level of a rule:

Rule 2: A program is a human-readable essay on problem solving that also happens to execute on a computer.

By this definition, a program is, at its core, an essay on problem solving. It is a set of instructions for solving a problem.

Why do you think Punch and Enbody stress that it is, or must be, a human-readable essay?

What if you are not a programmer, and not someone using programs to study ideas? The human-readable element of a program won't matter to you at all. You are most interested in the fact that a program happens to execute on a computer. The program gives a set of instructions for solving a problem, and the computer solves your problem!

In Session 1, we ran a steganograpy program that hid one image inside another. But we never looked at the program itself. All we cared about was its execution.

We have seen two little programs already in class. Also in Session 1, we saw a program that computed total mileage for me when I use my exercise bike at home. Then, in lab yesterday, we saw a program that computed the area and circumference of a circle. The code for these was "human-readable", but you probably didn't understand all of it. You haven't learned the language yet.

Even so, we were able to give it to the computer and use it solve problems:

program → [interpreter] → result

No matter how simple or complex, each program runs in basically this same way. Let's start learning more about our language and our tools, so that we can read and write programs, too.



The Python Programming Language

languages for writing programs
different vocabulary and grammar (syntax)
different kinds of terms, meanings (semantics)
simple/complex, better/worse suited for certain tasks

our language: the Python language
particular vocabulary, grammar, meanings
   program → [interpreter] → result
   --- the shell !
we will spend a lot of class and lab time in the shell
it allows us to "speak Python" and see the results of
   our programs -- like a conversation partner
talk to it often


A First Look at the Elements of Python

let's look at our programs from Lab 1 and Day 1
ask questions !

Day 1: solve problems by representing and manipulating *data*

Lab 1: a sequence of Python expressions ...

numbers and strings
  - integer and real
  - sequences of characters
    - character!
  - "literal"

name for value:
  - math.pi
    - math is a module:
      a set of Python commands someone else wrote and
      that we reuse by "import"ing it into our programs
    - interpreter substitutes value for the name
  - circumference
    - a name created by the programmer
    - interpreter does the same

manipulating: operations
  + and *
  **
  math with strings? +, *, **
    ("Eugene " + "Wallingford ") * 10
    "Eugene " + "Wallingford " * 10


Some Thoughts on Taking the Course

installing Python on your computer
  runs on Windows, Mac, Linux ...
  widely-used language both in and out of CS
  straightforward to install
    Appendix A
  can follow link on Resources page:
    https://www.python.org/

how to succeed
- practice
- use the shell when reading code
- use the shell to practice
- ask questions
- work at a steady pace


Wrap Up



Eugene Wallingford ..... wallingf@cs.uni.edu ..... August 28, 2014