CIT 591 Python Warm-Up Exercises
Fall 2011, David Matuszek

  1. [Get started] Log in. Start IDLE. Compute 2+2.

  2. [Write a program] From IDLE, open a new window (File -> New Window, or ctrl-N). Write a program to compute and print the result of adding 2 and 2. Save this program (File -> Save or ctrl-S) on a file named, then run it (Run -> Run Module, or F5).

  3. [Edit a program] Edit your program to compute and print the result of 13 squared. (You can use 13 * 13, or 13 ** 2 to compute this.) Run the program.
  4. [Use an if statement] Write a program to ask the user for a number, then print "number is even" if the number is even, or "number is odd" if the number is odd. (Print the actual number instead of number.) A number is even if the remainder (%), when divided by two, is zero. Save your program on a new file with any name you choose (but it must have a .py extension) and run it.

  5. [Use a while loop] Write a program to repeatedly do the following: (1) Ask for a number, and (2) print out a message that says what number you entered, and the square of that number (for example, 5 squared is 25). Quit when the number 0 is entered.

  6. If you have completed all the above and are waiting for the rest of the class to catch up, here's something more for you to work on:

  7. [The "Buzz" program] Write a program that prints out the numbers 1 through 100, except that, if the number contains a 7 or is divisible by 7, (or both), print the word buzz instead. Here are some programming hints:
    1. A number is divisible by 7 if the remainder, when divided by 7, is zero.
    2. A number ends in a 7 if the remainder, when divided by 10, is 7.
    3. A two-digit number has a 7 as its first digit if the result of dividing by 10 is 7.
    4. The (three digit) number 100 doesn't contain a 7, and that's as high as you need to go.
    5. Remember the if...elif...elif...else kind of statement.
  8. [Multiplication table] Write a program that prints out the multiplication table, for numbers 2 through 9.