Monthly Archive: October 2009

Midterm Reminder

The midterm for CPSC 217 will be Thursday September 29th @ 6PM in Science Theatres 148. Don’t forget to bring the always important identification, as in large midterms, someone will usually check this, and have you sign off that you were there.

Dr. Stephenson has posted 3 previous exams that you may want to look at to use as practice for this exam. (CPSC 217 Fall 2008, CPSC 231 Winter 2009 and CPSC 217 Spring 2009).

Assignment 2 Reminders

Assignment 2 is due on Monday, October 26th at Noon. Get a good start on it now, as there is very limited time for extra help on Monday.

Don’t forget to follow the specifications given in the assignment including:

  • Your program should follow good programming practices including:
    • meaningful variable names
    • avoiding the use of magic numbers (this means using numbers directly in your formulas, a better method would be assign those numbers to variables with meaningful names, and use those variables in the formulas)
    • including adequate comments
  • include a comment at the top of the file including:
    • with your name
    • student number
    • a brief description of the purpose of your program
    • Your TAs name or Tutorial number, should they get mixed up
  • Your program MUST be submitted both on paper and electronically.
    • For electronic submissions, name your file FirstnameLastname.py (substituting your own first and last name – please use a capital letter on each name) and email it as an attachment to Dr. Stephenson at the Email address listed in the Assignment 2 Specifications
    • Paper submissions, consisting of a printed copy of your .py file, should be deposited in the appropriate assignment drop box. My assignment boxes are marked with CPSC 217, J. Starke

For Loop Examples

The first example from this week was a count down. This would display on screen a count down from 10 to 0. The important thing from this example was

#Our looping Conditions
start = #what value do we want to start with#
end = #at what value do we want to stop#
inc = #how do we want our values to change from one to the next#

for i in range(start,end,inc):
     #Do something

In many ways, this behaves like the intersection example from last week. If our start were 10, and our end were 0, and our inc was -1, we would go down one number each time from 10 to 1 (remember, we won’t do anything with 0, cause we stop) The second example this week was a mathematical table. In this example we will have the numbers from 0 to 15 as a header row, and column. We will then will in the position at the row and column with the multiplication of the row and column header. In this example we use a nested for loop

#loop conditions
start = #where to begin#
end = #where to end#
inc = #how to change from one to the next#

for i in range(start,end):
     for j in range(start,end):
          #Do something with a combination of i and j

While loop Example

The intersection while loop example from last Wednesday and Thursday’s tutorial is available here

The most important thing in this example is the following

# Where do we want it to start
start = #Fill this in#

# Where do we want it to end
end = #Fill this in#

# How much do we want our loop to increase by each time
inc = #fill this in#

i = start
while i < end:

     # The body of your loop goes here

     #Don't forget to increase your i value by whatever amount you decided above
     i = i + inc

Assignment 2 Information

If you have not already done so, You should look at Assignment 2. This assignment is not extremely hard, but you may find it tricky in a few places.

The first thing you will need to figure out is the difference between the way points are mapped on the computer display, and the Cartesian co-ordinate system. The Cartesian coordinate system is the same one that you will likely have been working with in your math classes for years.

Second, you will need to algorithmically perform a number of operations. For this, I recommend a while loop. this will look something like the following:

x = 0
while x < 100:
     print x
     x = x + 1

This specific piece of code will print the numbers from 0 to 99. The important thing here is the x < 100 will work exactly like if we used an if statement. That is, it will keep doing the print, until x becomes 100.

Another tool you will likely find useful is doing powers in Python. So for example, your assignment you have y = ax3 + bx2 + cx + d. To do this, we first need to be able to calculate x3. As an example, if I want to just do this, and set it to a variable called x_to_the_3, the code would look like:

x_to_the_3 = x**3

Also, at the end of your program, you will need to see if the user wants to stop. To do this, we will again print to the screen, like we have on previous assignments, but the input on this assignment is different, and looks like:

user_input = raw_input()

user_input here will now contain a string that we can compare to what we expect the user to type in.

You may also find it useful to send somethings to QuickDraw before others. When you have already used print to send some things to QuickDraw, and you want it to send them to screen right away, you can use:

sys.stdout.flush()

This basically tells python, everything you have ready to print, send it now. When QuickDraw receives it, it will draw.

Finally, for those of you who did not use QuickDraw’s Text features on the last assignment, you will want to look into it for this assignment.

No Tutorial Monday (October 12) and Tuesday (October 13)

There will be no tutorials on Monday (October 12) and Tuesday (October 13) due to the Thanksgiving Holiday. Wednesday and Thursday tutorials will resume as normal.

If Statements

Here are 3 examples of using if statements in python.

Example 1 takes 1 variable, and checks it against 3 different conditions. Specifically, it checks if the input is negative, positive or 0.

Example 2 takes 1 variable, that is an hour of the day in 24 hour clock, and describes if it is morning, noon, afternoon, evening, night, or midnight.

Example 3 takes in 2 different variables, and says which one is bigger, or if they are the same.

Assignment 1 Submission

Just a few reminders for everyone about assignment submission. These are helpful reminders, they are not to be taken as a complete list of requirements.

Your program should include appropriate comments, including a header which includes your name and student number and describes the purpose of your program. There should also be comments within the program that indicate where the different parts of the face are drawn (eyes, nose, hair, ears, mouth, etc.).
Variables and constants should be named appropriately.

Hardcopies (printed or written) of Part 1 and 2 of the assignment need to be placed in My dropbox (J. Starke). These are due at 12 noon and will be picked up shortly there after. Your program should be named in the form FirstnameLastname.py, these should then be emailed to Dr. Stephenson, to his email address listed in the assignment specs.

Be sure to include your name on both Part 1 and Part 2, and staple all parts together.

To print your assignment in the lab, type in

lpr [your assignment file]

Next you will need to go to the printing station near the MS 160 lab. You will need to log in to the computer at the print station and select the files to print.

The drop post for my tutorials are located on the Second floor of Math Sciences. You can find them when you exit the stairs, by taking a right, going past the elevators, then taking a left, and they will be in the corner.