Due by class time Wednesday, February 1
The exercises below will give you extra practice with Python, but you do not need to turn them in. However, if you have never programmed before, I would strongly recommend doing them.
Read through this online tutorial to get started using IDLE. Note: this tutorial is a little out of date, but most of the information is still valid. You can start IDLE on the Pomona machines by simply typing idle at the Linux prompt.
Exercises 1-5 on pages 22-23 of the Python textbook.
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.
Exercises 1-4 on pages 71-72. Try these out interactively in Python, typing them in exactly as shown.
The following problems should be turned in. Most of them are from your first lab. Using IDLE, create a new file named assign1.py and put all of your program definitions in this file. That way, you can load them all into Python at once for testing by simply pressing the [F5] key.
Problem 8 on page 49: temperature conversion. Call your program farenheit() instead of main(). Hint: 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.
>>> farenheit() Enter a temperature in Farenheit: 212 212 degrees Farenheit = 100.0 degrees Celsius >>> farenheit() Enter a temperature in Farenheit: 0 0 degrees Farenheit = -17.7777777778 degrees Celsius >>> farenheit() Enter a temperature in Farenheit: 32 32 degrees Farenheit = 0.0 degrees Celsius >>> farenheit() Enter a temperature in Farenheit: 72 72 degrees Farenheit = 22.2222222222 degrees Celsius >>>
Assuming that 1 minute of time is worth $25 (surely a gross understimate!), 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().
Problem 1 on page 72: volume and surface of a sphere. Call your program sphere(). The constant pi is available as math.pi (no parentheses) in Python's math library. To use the math library, put the command import math at the top of your file.
Problem 2 on page 72: pizza cost. Call your program pizza().
Problem 9 on page 73: area of a triangle. Call your program triangle().
Problem 11 on page 74: sum of first n natural numbers. Call your program sumFirst().
Problem 12 on page 74: sum of cubes. Call your program sumCubes().
Problem 13 on page 74: sum of numbers entered by user. Call your program sumUser(). Hint: Use an extra variable called total, initialized to 0, to keep track of the running sum. The structure of your program will be similar to the previous ones.
Problem 14 on page 74: average. Call your program average().
Problem 16 on page 74: Fibonacci numbers. Call your program fib().
Save all of your program definitions in a single Python file called assign1.py.
Submit your file by running the command below from any Pomona Linux machine. Be sure to run this command from the directory containing your file.
/common/cs/submit/cs30-submit
You will be prompted for the assignment and the name(s) of the file(s) you wish to submit. A confirmation message will be emailed to you shortly afterwards telling you whether the submission was successful.
Alternatively, if you work on your own machine and would like to submit your file via email instead of the above command, that is possible but a little more complicated. Paste the entire plain text contents of your file into the body of the email message, and create a Subject line that looks exactly like this:
Subject: course<cs30> hw<hw01> user<yourUsername> file<assign1.py>
Send this email to the address cs30-submit@dci.pomona.edu
More detailed information on the cs30-submit script can be found here.
If you have questions about anything, don't hesitate to ask!