Homework 1

Due by class time Monday, September 11

Read Chapters 1-3 of the textbook, and go through this online tutorial to get started using IDLE.

Practice Exercises

  1. Exercises 1-5 on pages 22-23 of the Python textbook.

  2. Exercise 4 on page 48. Try these out interactively in IDLE at the Python prompt. Make sure to type each one exactly as shown, and make sure you understand the resulting behavior.

  3. Discussion questions 1-4 on pages 71-72. Try these out interactively in IDLE, typing them in exactly as shown.

Programming Exercises

Using IDLE, create a new file named assign1.py and put all of the following program definitions in this file. This way, you can load them all into Python at once for testing by simply pressing the [F5] key.

  1. Write a program to convert Farenheit temperatures to Celsius. Use the Celsius-to-Farenheit program shown on page 28 as a guide, but call your program temperature() instead of main(). The formula for converting Farenheit to Celsius is C = 5 (F - 32) / 9. Here is a sample Python session showing the kind of output your program should produce. Input typed by the user is shown in boldface.

    >>> temperature()
    What is the Farenheit temperature? 212
    212 degrees Farenheit = 100.0 degrees Celsius
    >>> temperature()
    What is the Farenheit temperature? 0
    0 degrees Farenheit = -17.7777777778 degrees Celsius
    >>> temperature()
    What is the Farenheit temperature? 32
    32 degrees Farenheit = 0.0 degrees Celsius
    >>> temperature()
    What is the Farenheit temperature? 72
    72 degrees Farenheit = 22.2222222222 degrees Celsius
    >>>
    
  2. Assuming that 1 minute of time is worth $25 (surely a gross underestimate!), write a program to convert time into money. Your program should ask the user for the number of minutes to convert, and then print out a message giving the equivalent dollar amount. Be sure to test your program on several different input values. Call your program time2money().

  3. Problem 1 on page 72: volume and surface of a sphere. Call your program sphere(). The constant pi is available as math.pi in Python's math library. To use the math library, put the command import math at the top of your file.

  4. Problem 2 on page 72: pizza cost. Call your program pizza().

  5. Problem 9 on page 73: area of a triangle. Call your program triangle().

Turning in Your Homework

Print out your assign1.py file and turn this in to me on Monday. You do not need to turn in your answers to the practice exercises.

If you have questions about anything, don't hesitate to ask!