CS 111 - Introduction to Computing, Spring 2017

Lab 1

For this assignment, we will write a simple Python program in the JES environment. You should look at the example program lect0119a.py that was written in lecture on 1/19. This program shows the basics of output and calculations which you will need to do for this program.

The JES Environment

The JES Development environment can be download from the main CS 111 Web Page.

Running JES on SOME machines in the ACCC Labs

JES can be found on SOME OF the machines in the ACCC Labs. Not all of the ACCC Labs have this software installed.

  1. clicking on the Start button (lower left corner of the display)
  2. clicking on the Programming folder
  3. clicking on the JES RXXXX application (where XXXX is the release number of the software)

Python Programming

When doing Python Programming, it is very important to follow a basic Python Template. Below is a file called template.py. Note that this wiki site does not keep indentation. However, indentation is very important in python. To help with this the spacing text of "<nbsp>" is placed into the below to show indentation. Please note that <nbsp> is not part of the python language and should not be part of your (or any) python program.

# This is a comment to describe the below program
# This program is being written for CS 111 for Assignment X
# Author: Your name here
# Date: Today's Date

def functionName ():
<nbsp> # place code here
<nbsp> # pay attention to indention! VERY IMPORTANT IN PYTHON!!!

<nbsp> # create and intialize variables first

<nbsp> # do any needed calculations

<nbsp> # print results

Output in Python

To output to the screen, we use the print function. Between the parenthesis, we place the information that we wish to display. To display a string of values (i.e. words), we place the words in double quotes. Such as:

     print ("Hello.  Hope you have a good day.")

You should also note that in python you can omit the parentheses to get the same result.

     print "Hello.  Hope you have a good day."

To print out a number or the value of a variable, we place that information between the parenthesis. For example:

     print (57)
     print (number)

We can print both some text and a value by placing both of these in between the parenthesis and separating them with a + sign, such as:

     name = "Bill"
     print ("The name is " + name )

The + sign when used with two strings will concatenate them together (join them one right after the other) so both values get printed out with one print statement.

To do this with numeric values, we must rely on the python function of "str( )" which will represent the numeric value as a string value. This is used as follows:

     number = 42
     print ("The answer to the ultimate question is " + str ( number )  ) 

The function str DOES require the use of parentheses. It is often better to over-parenthesize rather than under-parenthesize. Thus when given the option of having or NOT having parentheses, it is often better to use the parentheses.

Also note that to print a blank line in the output (i.e. to skip a line), use print() with nothing between the parathesis.

     print  ("")

Both produce the same result. You will notice that often the same result can be produced via different approaches.

We can also print out multiple values by separating the values with a comma in the print statement. This removes the need for the + operator and the str() function. However an extra space is added to the output. In most cases the extra space in no big deal (or even a good thing). So the above print statements could be rewritten as:

     number = 42
     print ("The answer to the ultimate question is" , number  ) 

Lab Assignment 1

Due: Wednesday 1/25/2017 by 11:59 pm (i.e. midnight)

Write a Python Program that will contain a function called main( ). This function is to do the following:

  1. Print out your name
  2. Print out your net-id
  3. Print out CS 111
  4. Print out your lab time
  5. Print out the additional information as described below:

As I Was Going to St. Ives

"As I was going to St Ives" is a traditional English language nursery rhyme which is generally thought to be a riddle.

The most common modern version is:

As I was going to St. Ives,
I met a man with seven wives,
Every wife had seven sacks,
Every sack had seven cats,
Every cat had seven kits,
Kits, cats, sacks, wives,
How many were going to St. Ives?


The answer to the riddle is commonly thought to be 1, the narrator of the rhyme. The man, wives, cats and kits are thought to be going the other way (i.e. coming from St. Ives). You can check out the Wikipedia page on this for more information than you would ever need to know.

For the final output of the lab, print out the information about who the narrator "met" while going to St. Ives. That is, print out:

  • The number of wives
  • The number of sacks
  • The number of cats
  • The number of kits (note: "kits" is short for "kittens")
  • and, the total number of living things met
    i.e. totaling the man, the wives, the cats and the kits (the sacks are not living things)

    You are required to use variables, multiplication and addition operations to calculate and determine the answers. For example:
    #declaring variables 
    numMan = 1 # determining the number of men 
    numWives = numMan * 7 # determining the number of wives 

    Just storing the value of 7 into the variable numWives is NOT enough for full credit for the assignment.

You are also required display the values in the variables when showing the information about who the narrator met. When doing this you must also display some text describing any values prior to displaying the values. For example:

print "The number of wives are:" , numWives

Submission of the Lab

The lab must be submitted electronically to the Assignment Link for Lab 1 inside of Blackboard. You will only need to submit the python source code file (this is the ".py" file).

You are to name your program file (and the class) using both your NET-ID and the Lab Number. Thus for Lab 1, if you NET-ID was ptroy4, your program should be named: ptroy4Lab1.py

Topic revision: r1 - 2017-01-23 - 02:14:17 - Main.troy
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF