CIT 590 Python Warm-Up Exercises
Spring 2013, David Matuszek

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 `test.py`, 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.
• `if `IDLE asked you to save the program before running it, do this`:`
Options -> Configure IDLE... -> General -> At Start of Run (F5) -> No Prompt.
Change the program to compute 14 squared, and run it again.
```else:     pass  # do nothing```

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. [Use a for loop] Write a program to print out the numbers 1 through 25 and, for each number, print its square and its cube on the same line.
7. [Write a function] Write a function named `buzz` that, given a single integer as a parameter, returns either the number it is given, or the word `"buzz"` if the number contains a digit 7 or is divisible by 7. 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.
6. Remember to `return` your result.
You can try out your function by entering, for example, `buzz(25)` in the Python Shell window.

8. [The "Buzz" program] Using the `buzz` function, 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), the program prints the word `buzz` instead.