Today's lab will focus on using the Gradescope system and simple programs in Python.

Software tools needed: web browser and Python IDLE programming environment.

Computers in CSci 127 Lab

CSci 127 has a laboratory, 1001E North, dedicated for its use. The room has a flexible set-up to encourage group work and laptop computers that can be checked out for use in the room only. When you enter the room, hand your Hunter ID to undergraduate teaching assistant in exchange for a laptop computer. At the end of lab, make sure to return your computer to its docking station so that it can be charged.

The laptops run Ubuntu Linux operating system. When you open the laptop, choose the "Computer Science Guest" account (the password is: 1001E!88). On the left hand side is a bar of icons, including icons for a browser (for accessing webpages) and the terminal window (for writing commands and launching programs).

When you launch the browser in the lab, you will see the standard HunterNet webpage. Fill in the form with your Hunter credentials (the same that you would use to access the wifi from your own computer or phone) to access the internet. If you get a message that you are not connected to the internet, click on the internet symbol (empty quarter circle) in the upper right corner of the toolbar. Hover over the "More Networks" and then click on "HunterNet". The wifi symbol will blink with concentric lines. When it stops blinking and becomes solid lines, an internet connection has been established and you can then reload the webpage to type in your Hunter credentials.

Using Blackboard

This course will use the on-line Blackboard system for course announcements, lecture previews, and posting grades. Blackboard should be accessible through your CUNY First account (see Hunter ICIT Blackboard page for directions on using the system and how to get help). The lecture previews can be found under the Content menu (left hand side of Home screen).

Quizzes and Coding Reviews

Each week in the 1001E lab, there is an quiz and coding review. This week, we will have a quiz on the academic integrity policy of City University of New York. Your instructor will pass out a copy-- make sure to write legibly and include your name and EmpID, so that you get credit for the quiz. See the topics and deadlines for information about future quizzes and code reviews.

Using Python

We will be using the IDLE programming environment for Python, since it is very simple and comes with all distributions of Python (if you would prefer to use another programming environment, Spyder is loaded on the lab machines).

To launch IDLE:

Note: The following assumes you are working on one of our lab laptops (you can check out a laptop to work on in lab 1001E Hunter North) running the Ubuntu Linux distribution. If you are running another Unix-like operating system such as a different Linux distribution or MacOS, locate the terminal on your machine. If you are running on Windows, you can find instructions on how to obtain a Linux terminal on your computer at the bottom of Lab3. Instructions on how to install Python on your computer are provided at the bottom of this page.

Instead of using the shell window (where we can try things immediately), let's use a text window, where we can save our program for later and submit it to Gradescope (this is the basis of the first program).

  1. First, open up a text window: on the menu bar, choose "File" and from that menu, choose "New File".
  2. In that window, type:
    #Name:  ...your name here...
    #Email:  ...your email here...
    #Date: August 27, 2018
    #This program prints: Hello, World!
    
    print("Hello, World!")
  3. Save the program (using the "Save" under the "File" menu). When you save it, name it something that you will be remember for the future and end it in .py. For example, ps1.py. At the end of lab, save your programs to a USB drive, DropBox, or mail them to yourself.
  4. Run your program (using the "Run Module" from the "Run" menu).
  5. If it prints "Hello, World!" to the screen, then log into Gradescope (see notes below):
    • On the left hand menu, choose "Assignments".
    • From the list, choose "1. Hello, World!". In the file upload, drag over the .py file you just created and ran, and
    • click "Submit".

Using Gradescope

This course will use the on-line gradescope system for submitting work electronically. An email invitation to the course was sent to your email address (we used the one saved for you on Blackboard as of Monday, 26 August). If you did not receive the email, one of the teaching staff can regenerate it for you.

More Python: Turtles

Now that you have just submitted your first program, let's try some other Python commands. Here's a quick demo (click the triangle to run the program):

A quick overview of the above program:

Now, let's write the same program in IDLE:

  1. Open up a new file window in IDLE ("File > New File").
  2. Type (or copy) into your window:
    import turtle
    tia = turtle.Turtle()
    for i in range(4):
        tia.forward(150)
        tia.right(90)
    
  3. Save your program ("File > Save").
    Note: Choose a name for your file that is not turtle.py. When executing the "import turtle" statement, the computer first looks in the folder where the file is saved for the turtle module and then in the libraries (and other places on the path). So, it thinks the module is itself, causing all kinds of errors. To avoid this, name your program something like "myTurtle.py" or "program2.py".
  4. Run your program (using the "Run Module" from the "Run" menu).
  5. Change your program so that it draws a decagon (10-sided polygon).
  6. Test your program and modify until you have a decagon. When you do, add comments at the top of your program:
    #Name:  ...your name here...
    #Email: ...your email here...
    #Date: August 25, 2017
    #This program draws a decagon.
    	
    Run your program after editing to make sure you do not have any typos.
  7. Log into Gradescope (see notes above). On the left hand menu, choose "Assignments". From the list, choose "2. Decagon". In the file upload, drag the .py file you just created and ran, and click "Submit".

More Turtle Commands

To review, we introduced the turtle commands:

as well as importing the turtle package (import turtle) and creating ("instantiating") a turtle (thomasH = turtle.Turtle()).

There are many more turtles commands. Over the next couple of classes, we will use those in the turtle chapter from the textbook. In addition to the ones that control movement, you can also change the color of the turtle, change the size of the drawing pen, and change the backbround color (by making a window or screen object, and changing it's color):

A complete list of turtle commands is part of the Python 3 documentation.

What's Next?

Since the lab computers are shared, student files are regularly removed from the computer. Any of your work that you would like to save, you should email to yourself, put in your dropbox, or save on a USB drive.

If you finish the lab early, now is a great time to get a head start on the programming problems due next week. There are instructors to help you, and you already have Python up and running. The Programming Problem List has problem descriptions, suggested reading, and due dates next to each problem.

Using Python on Your Computer

The Python programming language and IDLE environment are freely available for many platforms from python.org. For this class, we are using Python 3. Many features of the language (including the syntax of print statements) changed between the second and third version, so, you must use the Python 3 for submitting programs.

Linux:

If you have a Linux machine (Ubuntu or Debian based) and would like to match the environment on the lab machines, at a terminal window, type the following commands:

 sudo apt update
 sudo apt -y upgrade
 sudo apt install python3 python3-pip idle3
 pip3 install numpy pandas matplotlib scipy folium image
 sudo apt install spyder3

Windows:

If you have a Windows computer, you can install python3 with the following instructions:

  1. Go to the following link.
  2. Click latest Python 3 release.
  3. Scroll down to the files section.
  4. Click Windows x86-64 executable installer and save the file.
  5. Once it is finished downloading, run the installer.
  6. Make sure you click Add Python to PATH (This makes it a lot easier to install Python packages).
  7. Click install now.
  8. If asked do you want to allow this app to make changes to your device, click yes.
  9. Wait until you see the setup was successful screen and then you can hit close.
You have successfully installed Python on your computer. To open IDlE, search IDLE in the Windows search bar.

macOS:

If you have a Mac computer, you can install python3 with the following instructions:

  1. Go to the following link.
  2. Click latest Python 3 release.
  3. Scroll down to the files section.
  4. Click macOS 64-bit installer and save the file.
  5. Once it is finished downloading, run the installer.
  6. Hit continue, continue again, continue again, and then agree.
  7. Click install.
  8. Enter your password or use TouchID if prompted.
  9. Wait until you see the installation was completed successfully screen and then you can hit close.
  10. You can keep the install or move it to the trash.
You have successfully installed Python on your computer. To open IDlE, search IDLE in Spotlight search or find it in Launchpad. To open IDLE from terminal, type idle3.

Python Packages:

You can install the Python packages used in this course with the following instructions:

  1. If on Windows, search cmd in the Windows search bar and open it. If on macOS, search terminal in Spotlight search and open it.
  2. Install the Python packages with the following command:
     pip3 install numpy pandas folium image matplotlib scipy 

These installation instructions were written by Owen Kunhardt. You can find the full guides at the following links: Windows macOS

Alternatively, there are many free on-line versions that you could use via a browser, such as pythonanywhere.