CM151 Lab -- Getting Started


Lab Goal:

Your first lab assignment is to familiarize yourself with the programming environment that we are using this semester. If you are reading this on the CS lab machines, you have successfully logged on and used your account name/password combination.

You are encouraged to talk with others around you if/when you encounter problems, but each student should submit their own lab. (In future labs, you will be able to work together in small teams.)

The important things for you to learn in this lab are:

  • setting up your environment
  • navigation of the folders including creation of folders
  • downloading of files to your directories
  • starting up the python editor (IDLE3)
  • creating and running a small python program
  • upload your completed assignment to moodle

Setting Up Your Environment:

You have the option of using your own computer, or using any of the computers in lab. Our computers run Linux, which has the reputation for being more complex than Windows or MacOS. (Linux is user friendly, but is very picky about who its friends are!) Linux is actually relatively intuitive, once you get a little experience. This lab will assume you are using one of the Linux computers, but you should be able to follow along with your own computer as well. (Also, see Appendix B of our book for a more Windows-focused discussion of using IDLE.)

On Linux, one issue is finding where all the tools are, these can be found in the funny circle widget along the top or bottom of the screen. Click on this and you will see all the various programs in menus. If there is a program you would like to add to your screen, just point at it and right-click. There will be an option that will allow you to add that item to the toolbar.

Try adding the terminal program, from the Accessories submenu, to your main screen. The terminal is a text entry program and is the easiest way to start different programs.


Navigation of folders:

  1. Create a folder called cm151 in your home directory. (There is a GUI directory browser available.)

  2. Create another folder called lab1 within the folder cm151, i.e., lab1 is a sub-folder of cm151. You should always create a folder for each lab assignment and name it accordingly.

  3. Download the following example program (example1.py) to the folder lab1


Assignment:

  1. Starting up the Python Environment and Running a Program:

    • open a terminal window by clicking on the Terminal item you created.

    • go to the directory you want to work in (e.g., cm151/lab1) by using the change directory command (cd)
      cd cm151/lab1

    • start up the python editor using the following command
      idle3 -n &

    • Open the file you want to edit (e.g., example1.py)
      • change the name (and hometown) in the file to your particulars
      • save the file
    • You can run your program one of two ways:
      • within IDLE, select from the menu 'RUN' followed by 'Run Module', or
      • within the terminal window, run the program
        python3 example1.py
  2. Playing with the Chaos program:

    • Create a new file called chaos.py in your lab1 directory.

    • In the new file copy in the program from pages 12-13 of the text book. Yes, it would be easier if I just gave you this code in electronic form, but I'm asking you to type it in to begin getting familiar with Python. As you type, you should be trying to figure out how the different parts of the code (may) work.

    • Note that the first few lines of the file contain the # at the begining. This is a comment character and ignored by python. Using those first few lines as examples, create a new line that contains your name. This is good form, and will make sure that Matt easily knows whose code he's reading while grading.

    • Modify the chaos program to print 20 different numbers, instead of just 10.

Submission

Once you have completed the two assignments, submit your two .py files to the CM151 moodle site for lab 1.