CS I - Lab 01

Tuesday, January 15th

Objectives:


Yesterday we talked about the fact that our theme for this course is "The computer as a tool."  In order for you to study how the computer is like a tool – and how you can program it to build even more tools that do things specifically for you – you need to understand some of the functionality of the computer and to explore some of the existing tools that you will be using. 

This semester we will be using a networked computer lab as the base tool for our exploration.  The first part of this lab will have you test your account on that network to confirm that everything works properly

The second part of this lab will have you use the Internet as a tool to explore the resources available to you and research answers to some of the "historical" issues I asked you about during class yesterday.

Part A: Logging on and Setting up

Logging on to the CNS network

  1. Locate a free computer in Wright 112 (these same procedures will work in the lab in Wright 339)

  2. The computers in this lab are “dual boot” - that is, they run both Windows and Linux. We will be using the Windows side of things. If you happen to sit at a computer that is booted into Linux then you will need to reboot the machine into Windows (You will know you are in Linux if the login screen is titled “GNOME Desktop Manager). To reboot the machine

  1. Once you are sitting at a computer that is booted into Windows, you will need to log on:



Creating a directory for this class

You will actually use two different computer networks as part of this class. You will use the labs in Wright Hall for lab on Tuesdays and probably for your homework/programming assignments. You will also use a laptop in lecture somedays in ITTC. In order to keep your files for this course together and in a place where they can be easily accessed from either location, you will want to create a couple of folders for your course materials.

  1. Open up the graphical representation of the computer by selecting "Start | My Computer " or selecting My Computer from the desktop

  2. Select (double click) on the icon for the network drive named “Math-CS” that should be towards the bottom of this window.

  3. When this drive opens up notice that the address field says “P:\” For this reason I will refer to this as the “p drive” (tricky, I know!)

  4. Select the icon labeled “810:059-Python” This is the directory for this course.

  5. Select the icon for the folder labeled with your username (I entered these in by hand, so if I typed something wrong, please let me know).

  6. Create a new folder in this directory and give it the name mediasources.  You can do this by right clicking in the empty area and selecting “New | Folder” and then renaming the folder that is created.

  7. Use the "Back" button to return to examining the contents of the course directory.

  8. Select the directory labeled “common_mediasources”

  9. COPY the two files from this common_mediasources directory (logo.jpg and fanfare.wav) and paste them into the mediasources directory you just created in step 6. Again, please COPY these files so everyone has access to them.

  10. Now you should be ready to explore one of the main tools we will use this semester - JES.




Part B: Using JES as a Tool

During this course you will use JES (Jython Environment for Students) as a tool to explore programming.  JES is a free implementation of the Python programming language which includes a library of some non-standard Python commands to manipulate media files based on the materials in your textbook.  While you will not explore ALL of JES during today's lab, we want to get started so you have a little bit of a feel for how things work.

  1. Launch JES by selecting "Start | All Programs |  Programming | Python | JES"
  2. The first time you do this you may encounter one or more boxes asking you for registration information for an email based submission system that we will not use.  Therefore, you may select "ok" or "cancel" as appropriate to skip through these screens. 

When JES is finally fully loaded it should look like this:

JES has two main ways to write code (we call instructions for the computer "source code" or simply "code for short). 

The top part of JES is the "Program Area"  This is where you write code that you want to keep.  The Program Area lets you write code, store it to a file, and load it from a file later on.  It behaves like a very simple text editor (like Notepad or Microsoft Word).  While we will use this area extensively during this course, we will not use it very much in today's lab.

The bottom part of JES is the "Interactions Area"   This is where you write code when you are just trying stuff out and trying to see what things do.  Since this is the main point of today's lab, we will use this area today.


Hello World from the interaction pane

While this following example program is incredibly outdated, there is a traditional/historical first program, often referred to as "Hello World"  It's purpose - to simply print a simple message to the computer screen.  Your texbook shows the way this might be done in several different languages on page 6.  Because we are using JES and an interactions pane, we can make this even easier than the code described on page 6.

In the interactions area (the bottom window) type the following:

print "Hello World!"

When you hit Enter, JES goes off to interpret what commands you gave it.  In this case, it interprets your command as an instruction to print (to the screen, not the printer) whatever message is included inside of the quotes (in computer vocabulary we normally refer to the message between quotes as a String).


Syntax Errors

Of course, if you typed something into the interactions pane that JES doesn't recognize, you will get an error message.  To demonstrate this, type:

prin "Hello World!"

(notice that I mis-spelled print).  This gives you a message that should say something like:

Whenever you get a message like this, pay close attention to what I ASKED you to type and what you ACTUALLY typed.  While sometimes I might have a mistake in my lab, more often, you will have made a typo.


Playing around a little bit

Ok, all of that was pretty boring.  Let's personalize it a little bit.  Try typing in:

print "Hello Ben!"

(of course, you should replace MY name with your name so that you print "Hello Jason" or "Hello Kenny" or "Hello Mohammed" or whatever is appropriate for you).

 

[Q1]  Now, what do you think will happen if you type in the following:

print "Hello" + "Ben"

SideBar:  Frequently during labs you will see a special designation contained inside of square brackets like the [Q1] above.  In this instance, this indicates that I have asked you question #1.  This will correspond to a paper lab sheet that you will complete while you are in lab and submit as part of the credit for being in lab and completing the activities.  You should ALWAYS stop what you are doing and answer the question(s) before moving on.  For example, you should stop and answer this question BEFORE you type it into the computer.


 

[Q2]  Try it.  Did you guess right?  Look closely.  Exactly right???

 

Notice that python (like many languages) allows you to use the plus symbol (+) when dealing with Strings.  When you "add" to Strings together you perform "concatenation"

 

[Q3]  What would you need to modify in this command to have it print the way we expect it to be printed?  Try it out and make sure that you are correct.

 

[Q4]  What do you predict will happen when you type

print "3 + 2"

[Q5]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q6]  What do you predict will happen when you type

print 3 + 2

[Q7]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q8]  What do you predict will happen when you type

print "3" + "2"

[Q9]  Try it.  Were you correct?  If not, what was printed?

 

 

[Q10]  What do you predict will happen when you type

print "3" + 2

[Q11]  Try it.  Were you correct?  If not, what was printed?  What does this mean?

 

 

[Q12]  What do you predict will happen when you type

sum = "3" + "2"
print sum

[Q13]  Try it.  Were you correct?  If not, what was printed?  What does this mean?

 


Making sure that JES will work with image files

One of the other things that we talked about in lecture yesterday is the fact that we will be focusing on media computation this semester - the manipulation of sound and image files.  While we will do a lot of this later on this semester, I want to make sure that we aren't going to have any surprised when the time comes.  Let's make sure that your account and JES will open and "show" picture and sound files.

Type the following into the interactions pane

filename = pickAFile()

After a few moments a standard file chooser pop up should appear.  Using this, select the file "logo.jpg" that you saved onto your computer earlier in the lab.  Once this is done, type:

print filename

[Q14]  What happens when you type print filename?  What does this represent?

 

Now type:

picture = makePicture(filename)
print picture

[Q15]  What happens when you type print picture?  What does this represent?

 

Finally, type:

show(picture)

A small UNI logo should appear on your screen.  If it does not, please talk to an instructor.

 


Making sure that JES will work with sound files

Type the following into the interactions pane

filename = pickAFile()

Select the file "fanfare.wav" that you saved onto your computer earlier in the lab.  Once this is done, type:

print filename

[Q16]  What happens when you type print filename?  What does this represent?

Now type:

sound = makeSound(filename)
print sound

[Q17]  What happens when you type print sound?  What does this represent?

If you happen to have headphones with you, you can plug them into the headphone jack on the front of the computer and type

play(sound)

A small trumpet fanfare should be played over your headphones.  If it does not, please talk to an instructor.


Part C: Using the Internet as a Tool

The Internet has become a powerful tool for providing people with access to information.  We will use this tool FREQUENTLY in the class. 

This part of the lab is designed to exercise your ability to use the internet for both of these purposes.

 

Using the class website to gather information

If you have not already done so, use the web browser of your choice navigate to the course website.  Follow the link for the “Original Syllabus.”  (You were given a paper copy of this in class on Monday).  While reading the syllabus, answer the following questions.

 

[Q18]  What is the email address for the class mailing list?

[Q19]  What is the minimum grade you need to earn in this class if you want to take CS II?

[Q20]  How many points will you earn over the course of the semester?  How many of these are assigned during exams?

[Q21]  What is the URL for the University’s Academic Conduct policy?

 

I also post lecture notes to the website when appropriate.  On Monday I used Power Point slides in class.  These slides are posted to the website as well.  Open the slides from Monday and search for the following information.

 

[Q22]   What is the name of the cartoon character with the power drill?

 

 

Using other people’s websites to gather information

[Q23]  On your information sheet on Monday, I asked you to guess what year each of the following objects first appeared.  Using the search engine of your choice, search for these terms (or terms such as “history of computing).  Find sites that look credible and track down an “official” date for at least ten of the eighteen objects.  For each one that you find, list the date and the URL you used to arrive at that answer.

Object

Year first appeared

URL

Abacus

 

 

Slide rule

 

 

Four-function calculator (+, -, *, /)

 

 

Programmed mechanical computer

 

 

Programmable digital computer

 

 

The IBM PC

 

 

The Apple Macintosh

 

 

The computer interface with windows, icons, menus, and mouse

 

 

RAM chip of 1 megabyte or more

 

 

Hard drive of 1 gigabyte or more

 

 

The first high-level programming language

 

 

The LINUX Operating System

 

 

Telegraph network

 

 

Commercial radio

 

 

Commercial TV

 

 

The Internet

 

 

The web browser

 

 

First full-length feature move generated completely by computer

 

 

 

[Q24]  On your question sheet I asked you to identify your favorite subject and your least favorite subject.  For EACH of these subjects, find out how professionals in that discipline use computers to help them do their job.  Write a paragraph for each of these subjects.

 

[Q25]  On your question sheet on Monday I asked you to identify three computer scientists and explain (briefly) what they are famous for.  Do a little research to find out a little more about these people and write a paragraph for each below.  If you didn't come up with three, then select from the suggestions below for some ideas.

 

 

 


Finishing Up

At this point you should check over your activity report to make sure that you have answered all questions.  Once you are sure it is complete, you should turn it in and you are free to leave. 

 

Do not forget to “log off” of the machine you are working on.

 


Acknowledgements

Parts of this lab were taken from a "JES tutorial" written by Titus Winters and Josef Spjut.  Other sections of this lab are based on materials from your textbook.