CMPT 120 Lab 1

This site applies only to CMPT 120 D1 (Burnaby) in Summer 2011. See the other instructors' pages for other sections.

  1. Create a text file or answer this question on paper. Give an example of an everyday algorithm (other than the ones discussed in the Guide and in lecture).
  2. Check your algorithm against the four criteria listed from the definition of "algorithm" (Topic 1.1 in the Guide: unambiguous, solves a problem, legitimate input, finite amount of time). Does it miss any of these criteria?
  3. Start IDLE and create a Python program named hello.py prints the words "Hello world" on the screen when it's executed. [Yes, there is code in the Guide that does this. The point is for you to make sure you can use the tools.]

    Make sure you're doing this in an editor window in IDLE, not in the interactive interpreter. You should be able to save what you typed as a .py file.

  4. Create a Python program that sets the following variables to the corresponding values and then prints the contents of each of the variables.
    Variable NameValue
    course"CMPT 120"
    credits3
    pi3.1416
  5. Create a text file or answer this question on paper.

    What is printed by each of these statements? Do this without typing the code. You can confirm your answer with the IDLE interactive interpreter if you like.

    1. print "Hello" + " " + "World"
    2. print "The sum: " + str( 4+5+6 )
    3. print 15/4
    4. print 15.0/4
    5. print round(15.0/4)