Program 0

Computing Infrastructure

ICS-31: Introduction to Programming


Introduction This first "programming" assignment is not a "programming" assignment at all; it is designed to ensure that you know the fundamentals of using the computing infrastructure for this course, both on your own machine (if you have one) and the computers in our labs. Primarily it concerns starting to learn to use the Eclipse Integrated Development Environment (IDE) for Python. Knowing how to use these tools is a first important first step towards being able to learn how to program well.

Subsequent programming assignments will have much less of a cookbook flavor; instead, they will focus on designing, writing, testing, and debugging programs in Python from the specifications that I supply. But, these assignments will assume that you are already an experienced Eclipse user, who knows all the tools and skills covered in this assignment, and can easily apply them when writing his/her own actual programs.

So, treat this assignment very seriously: you will not want to still be learning this material at the same time that you begin writing your early programs. Now is the time to begin mastering these important tools and skills.

Finally, read and follow these instructions carefully. It would be an excellent idea to print a copy of this web page, read through it, and highlight any details that you think are important (and might forget as you are working on the assignment) or that you are confused about. Some students lose points for failing to follow directions properly; this is a problem that gets worse during the quarter, so starting out by doing the "right thing" in this assignment is an excellent idea. If you have any questions about these instructions, for example, if you think they are in error, or just confusing, please post on the appropriate MessageBoard Forum; and make sure you examine the posts from other students.

Finally, carefully read the last two sections, on Extra Credit and Time Management. These important sections are relevant to all programming assignments, but appear only in this one.


Part A:
Survey
On the day this program is assigned, you will receive an email from EEE asking you to fill out a survey; you can also click here to reach this Survey. There are a series of Informational Questions followed by a series of Graded Questions: please answer both.

Part B:
Create a New Project
and Script
Read the Python Programming in the Eclipse IDE web page (which is also accessible on the Handouts web page). It includes all the information that you initially need to know about using Python in the Eclipse IDE. This includes
  • Starting/Stopping Eclipse
  • Running the Python Interpreter
  • Creating Projects in the Eclipse Workbench: new ones and existing ones
  • Editing scripts
  • Correcting syntax errors
  • Running scripts
  • Correcting execution errors
Work through this document to understand Eclipse and gain some experience using it before starting this assignment. Ask your TAs/Lab Tutors questions; please cross the "question answering threshold" quickly; get into the habit of being able to ask them questions, especially in lab.

To do this assignment, you must have already downloaded and installed Java, Python, and the Eclipse IDE on your own computer (or be using one of the UCI Lab machines, where it has already been downloaded/installed). Follow the Download/Installation Instructions if you need to.

In Part B you will run the Python interpreter to compute an answer, create a new project in the Eclipse workbench, create a new (trivial) script (using the answer computed by the interpreter) without syntax errors, run it to ensure that it executes correctly, and finally submit the script on the Checkmate Homework Dropoff sytem. Here is a short checklist of things to do. If you are confused or run into problems with any one, ask for help as soon as possible.

  • Start Eclipse.
  • Start the Python interpreter in the Console.
  • Type the following expression into the interpreter; avoid the temptation to cut and paste this expression.
    '{0:,}'.format(2**100)
  • Create a new Python project in the workspace/workbench named project0b.
  • Create a new module in this project named demo: the module and file will actually be named demo.py; Eclipse automatically adds the .py.
  • Delete the comment Eclipse puts at the top of your module and replace it by your name and lab number: e.g.,
    # Peter Anteater, Lab 1 
  • After leaving a blank line, type the following Python script in the module: practice with the editor; avoid the temptation to cut and paste this code. Actually, for the big number in single-quotes, copy/paste the value that you computed in the interpreter after the comma but before the closing parenthesis.
    print('My first program: a hybrid')
    print('Answer (from Inteprxter) =', '1,267,650,600,228,229,401,496,703,205,376')
  • Fix any syntax errors that Eclipse shows (you might have introduced one by not entering the script corectly).
  • Run this script to ensure that it produces the correct output in the Console.
  • Finish the project by closing it in the Eclipse workbench, but do not delete it.
  • Find the Checkmate Home Dropoff link in the index of the course web and use it to drop off the demo.py file in the project0b folder in the workspace for Eclipse. If you need to, review the Checkmate Tutorial (which is also accessible on the Handouts web page).
  • Reopen the project and ensure that you can still (re)run it.
  • Finish the project by deleting it and delete all its resources; it is now no longer in the workbench or workspace.
  • Redo all these instructions, until you can do them quickly and easily; it would even be useful to practice removing this submission and resubmitting it, so you practice doing that in Checkmate.
  • Terminate Eclipse.
This part of the programming assignment is very cookbook, but by the end you should have mastered the steps needed in creating and manipulating project folders and script files with Eclipse and Checkmate -something you will do over and over again during the quarter (and possibly beyond, in ICS-32/-33).

Part C:
Debug an Old Project's
Script
In Part C you will download and unzip a project and put it the Eclipse workspace, create a project for it in the Eclipse workbench, correct the syntax errors in the script, run it, correct the execution errors in the script, and finally submit the script on the Checkmate Homework Dropoff sytem. Before beginning this part of the programming assignment, read the short handout on Bugs. Here is a short checklist of things to do. If you are confused or run into problems with any one, ask for help as soon as possible.
  • Start Eclipse (terminate it first, if it is currently running); notice the Workspace folder name in the Workspace Launcher pop-up window before you click its OK button.
  • Download the project0c project folder and unzip it to a folder on your desktop; it should contain one file named collatz.py.
  • Create a new Python project in workbench named project0c (using the project0c folder just downloaded and moved to the workspace).
  • Disclose this project in the PyDev Package Explorer and double click the collatz.py modules so that it is visible in an Editor.
  • Notice the two syntax errors marked in red on line 68 and 76.
    1. If the line numbers do not appear in the Editor, turn them on.
    2. If there are syntax errors on lines 55 or 56, you have not set up the course library correctly. Read the Course Library installation instructions before proceding.
    Fix the errors as specified below. You do not yet need to understand these errors or how to fix them, but we will cover the necessary material soon.
  • Fix the syntax eror on line 68 by placing a comma right after the token cycle_count and before the token ': test number is now'. If the red syntax error on this line doesn't quickly disappear, issue the right-click | Save command.
  • Notice that a new syntax error appears on line 71; it sometimes happens that one syntax error (line 71) is masked by another (line 68); when we fix one line, a new one shows an error.
  • Hover over the red syntax error icon on line 71. It says Expected:: which really is Expected: followed by the semicolon it expects. Although it underlines in the if token in red, the mistake is later in this line.
  • Fix the syntax eror on line 71 by placing an equal sign right after the equal sign on this line (no separating space): here we must have the == token. If the red syntax error on this line doesn't quickly disappear, issue the right-click | Save command.
  • Hover over the red syntax error icon on line 76. It says Undefined variable: test_number because we misspelled this name. It underlines this token in red.
  • Fix the syntax eror on line 76 by adding a b in the name: it is now spelled correctly as test_number If the red syntax error on this line doesn't quickly disappear, issue the right-click | Save command.
  • Now the script has no syntax errors, so we can run it. Enter 3 to the first prompt and just press enter for the second (it will use the default value of True).
  • Python will report show the script starting to run in the Console and then report an execution error.
    Enter a positive number: 3
    Display intermediate results[True]: 
    Cycle 1 : test number is now 3
    Traceback (most recent call last):
      File "C:\Users\Pattis\workspace\project0c\collatz.py", line 75, in 
        cycle_count += '2'
    TypeError: unsupported operand type(s) for +=: 'int' and 'str'
    It identifies an error on line 75, then shows the line, then reports the error, which relates to the fact that the += operator cannot be applied to an integer and a string.
  • Fix this error by changing the string literal '2' into the integer literal 2; now the += operator is adding two integers.
  • Run the script, and again enter 3 to the first prompt and just press enter for the second.
  • This time the script runs to completion, but it has an intent error. Notice that the cycle counts increment by two, not one; so our answer says it requires 15 cycles, but it only requires 8.
  • Fix this error in line 75 by changing the integer literal 2 into the integer literal 1.
  • Run the script, and again enter 3 to the first prompt and just press enter for the second. This time the script runs to completion with the correct answer.
  • Finish the project by closing it in the Eclipse workbench, but do not delete it.
  • Find the Checkmate Home Dropoff link in the index of the course web and use it to drop off the collatz.py file in the project0c folder in the workspace for Eclipse.
  • Terminate Eclipse
Again, this part of the programming assignment is very cookbook, but by the end you should have mastered the steps needed in creating and manipulating project folders and script files with Eclipse and Checkmate -something you will do over and over again during the quarter (and possibly beyond, in ICS-32/-33).

Bottom Line

You will be writing many programming assignments during the quarter, requiring you to create new projects or modify existing ones. You should be able to manipulate both kinds of projects easily in Eclipse, and submit them for grading in Checkmate.

Finally, whenever you want to check on a feature in Python or a library module, you should have a very low threshold for quickly starting Eclipse and using its Python Interpeter, or writing a small script, to experiment. It is imperative that you get comfortable with this process immediately.


Extra Credit Programming assignments must be turned in on time: you can get partial credit for a partially completed assignment, but it must be turned in on time; I will accept no late homework unless you have an official excuse pre-arranged with me (and even then I will always want you to turn in whatever work you have completed by the due date/time). In fact, there is another incentive to finish not only on time, but to finish early.

In all programming assignments, if you turn in everything at least 24 hours before it is officialy due, you will receive 1 point of extra credit. If you turn it in 48 hours (or earlier), you will receive 2 points of extra credit. (There is no more extra credit for early turn-ins; I recommend NOT turning it in more than 48 hours early.) This is equivalent to almost half a grade improvement (e.g., C+ to B, or B to B+, or B+ to A) on a 45 point assignment. I expect most of the students to complete their assignments and submit them early, so they will receive some amount of extra credit; it adds up.

There are two main advantages to planning on finishing early. First, if you run into a major problem, you will have extra time to solve it before the actual due date: and even experienced programmers frequently run into such problems. Yes, this means you! Second, and more importantly, if you are racing to finish before a deadline, stress levels can go through the roof, and you become less interested in learning the material (and the whole purpose of these programming assignments is to learn the material) and more interested in just getting it finished. If you do not learn the material, you will be at a major disadvantage for all subsequent programming assignments and tests, because of the cumulative nature of the material in this course. Therefore, work on an aggressive schedule and plan to finish every assignment by Tuesday or Wednesday evening.

Programming assignments sometimes also include an extra credit section worth 1-2 points. These are designed for students who finish early and want to continue exploring programming within the context of the assignment. The points are to acknowledge, in a very small way, their extra effort.

This assignment has no special extra-credit section. You can get extra credit on it only for an early dropoff.


Time Management One of the hardest parts of being in college is learning how to manage your time. Time management is especially important in programming courses (and in the real world, when you are working on complicated projects with hard deadlines). The difference between good and bad time management can have a profound impact on how much you learn in this course, how well you perform in it, and how much effort you actually need to expend to do well.

I will try to divide most programming assignments into a series of smaller tasks, each that can serve as a milestone; when solved in sequence, these tasks will complete the entire assignment. When we start writing programs, we will discuss such a divide and conquer method more formally, calling it iterative enhancement.

Generally, it is best to spread out the work on a week-long assignment. Most assignmnts become available on Thursday morning; I recommend reading the assignment during lab (the day it is discussed in lab) so that if you are unsure about any parts of it, you can ask relevant questions about them in lab; this reading includes running the executable files included with each assignment, to see how the program should behave (including its input and output -which you must match). You should start working on it during lab, and should plan to complete at least half the programming assignment over the weekend. You should finish it early the following the week: if not by Monday, you can use the lab on Tuesday to get finish it, asking questions of the starff during the lab.

Some students look at an assignment and think that it is best done in one sitting. If you can do so, great; but, if you plan to work this way, do the one sitting over the weekend, not Thursday night! In this way, if you are wrong about the amount of time that it will take, you will still have adequate time to complete the assignment.

Likewise, I have seen students who spend Thursday finishing the previous assignment, and not get around to looking at and starting the next one. This starts them on

By meeting these time goals, you will both maximize what you learn and minimize your anxiety and the time that it takes for you to do the learning.

Remember that assignments must be turned in on time: you can get partial credit for a partially completed assignment, but it must be turned in on time; I will accept no late homework unless you have an official excuse pre-arranged with me (and even then I will always want you to turn in whatever work you have completed by the due date/time).

Finally, if you find yourself falling behind, seek help immediately (from me, the TA, the Lab Tutor, or even other students in the course -when appropriate). When the real programs start, we will discuss what kind of help you can get legitimately, and what kind of help constitutes cheating.