CSC111 Lab 1
Feel free to work in group, share insights and help your neighbors during the labs. While some homework assignments will have to be done as individual work, the labs are a good time to cooperate with neighbors or work in pairs.
Login/logout
To login refers to the action of connecting to the computer as a user. To connect to Beowulf, the computer used for Computer Science classes, one must have an account and a password. Logout is the term used when you are finished with the computer and want to terminate your session. You should have a Unix account form at this point, and have found on it your account name (of the form 111a-xx, where xx are two letters, different for everybody), and your password. Using the Windows PC in front of you, find the SecureShell program/icon on the desktop (or via the Start/Program menu) and click on it.
If the Quick Connect window is not greeting you, click on the Quick Connect icon to get it:
Enter beowulf.csc as the host name, 111a-xx as your user name (change the xx to reflect your 2-letter Id) Click on the Connect button Enter your password. and click "Connect".
If everything went well, you should see this:
SSH Secure Shell 3.1.0 (Build 235) Copyright (c) 2000-2001 SSH Communications Security Corp - http://www.ssh.com/
This copy of SSH Secure Shell is a non-commercial version. This version does not include PKI and PKCS #11 functionality.
[111a-xx@beowulf ~]$
Keep your account and password information in a safe place, or learn both by heart! You will need them every time you need to use your account and work on your homework assignment or lab.
You may want to log out now, to practice this login procedure a couple times. If you are working with a lab partner, it is a good time to log out and let her/him try the procedure.
Call on the TA or your instructor if you need help.
Playing with the Emacs Editor
First execute this command from the Linux prompt:
getcopy .emacs
(That is "getcopy" space period "emacs") It's a configuration file that will allow emacs to understand the backspace key correctly. You only need to do this once and you will be set for the semester.
You will now get a copy of a file from your instructor's account, and edit it. The file is called Fulghum and is a short story from Robert Fulghum's book All I really need to know I learned in Kindergarten.
To get a copy of this file, type
getcopy fulghum
followed by the return key. Then edit the file with the command
emacs fulghum
Simply work on the first paragraph of the file, and try to straighten it up. I have indicated below, on the right-hand side, which emacs commands you can use to fix the text on your screen.
When you are done with the modification, or if you want to stop for right now and save your modifications, type C-x C-c, and press y when emacs asks if you want to save the file. Below is a summary of some useful emacs commands.
You should find some time this week to go to a lab and read the Emacs at Smith handout while in front of the terminal, on your own. This is the best way to test and learn the different features of the editor!
DEL/Shift Backspace Delete previous character c-d Delete character at cursor Esc-d Delete word c-k Kill line c-a Go to beginning of line c-e Go to end of line c-f Move cursor 1 character forward c-b Move cursor 1 character backward c-p Move to previous line c-n Move to next line c-x c-c quit emacs and save file c-x c-s save file but remain in emacs c-g GE OUT OF TROUBLE! Part I of the homework assignment for this week is to edit the complete story about Larry Walters and his flight over Los Angeles.
Creating your first Python program
You are now ready to create your first Python program. Don't worry if what you are doing does not make sense. We will go over all of these steps in details in class these coming weeks. Make sure you have exited emacs and are back to the Unix prompt. If you are still "inside" emacs, type c-x c-s to exit back to the Unix prompt.
Open a second SSH window. You will use one to edit your program, the other one to execute your program.
In Window 1, use emacs to create a file that will contain your program:
emacs first.py
Type in the following lines
- first.py
- 111a-xx (change and use your own account)
- firstname lastname
- My first python program
- Adds two numbers together and displays them
x = 5 y = 6 print "x = ", x print "y = ", y print "x+y = ", x+y
Type c-x c-s (control-x followed by control-s) to save the file. In Window 2, type in the following command at the Unix prompt to run the program:
python first.py
If you get a message of this form:
File "firstlab.py", line 5 print "x = " x ^
SyntaxError: invalid syntax
then you probably didn't type the program correctly. Make sure didn't forget double quotes or commas, and spelled all the words correctly.
You will know that your program works if you see it output x+y = 11.
Version 2 of your program
Modify your program so that it outputs the sum of three variables, x, y, and z, which you will have initialized with the number 5, 6 and 10. Use emacs to open your program as you did before, make the changes you feel are necessary. If you get stuck, don't hesitate to ask for help! Make sure your program works and outputs the correct output before moving on to the next part.
A Third Program
Once you are done with the first two programs, exit emacs, and at the prompt call emacs again, but this time give it the name of a new program:
emacs third.py
Enter the following lines:
- third.py
- 111a-xx
- first lastname
- prompts the user for first and last name, along with year of birth
- outputs approximate age
fname = raw_input( "what is your first name? " ) lname = raw_input( "what is your last name? " ) yearOfBirth = input( "What year were you born? " )
print "Hello", fname, lname print "you must be about", 2007 - yearOfBirth, "years old"
Once you're done, exit emacs and run your program:
python third.py
Verify that it works and gives you correct information. Modify your program so that instead of asking for the year of birth, the program asks for your age, and then outputs what year you were born in.
Homework #1
That's it for this lab! You are now ready for Homework #1! You can also get it by going to your instructor's Web page, http://cs.smith.edu/~thiebaut, and by clicking on the CSC111 shortcut.
Locate class page, then the week by week calendar, and the link to the first homework assignment. It is due the evening of Thursday Sept. 13th, at midnight.
Installing and using Secure Shell on a Windows PC or a Mac
The Smith College Technology Services Web pages have some good information on how to install the Secure Shell client on a Windows machine. Visit this page for more information. Carnegie Mellon University also has a nice page on the Secure Shell utility on a Mac running OS X. Just replace unix.andrew.cmu.edu with beowulf.csc.smith.edu in the tutorial. page on SSH for the Mac.