Next: About this document ...
Up: Homework 2: Variables and
Previous: Printing dates
- 1.
- Close the previous project and go through the process of
creating a new project, this time named Time.
- 2.
- Following the example in Section 2.6, create variables
named hour, minute and second, and assign
them values that are roughly the current time. Use a 24-hour
clock, so that at 2pm the value of hour is 14.
- 3.
- What do you think you should do here before going on?
See Step 2 above.
- 4.
- Make the program calculate and print the number of
seconds since midnight.
- 5.
- Make the program calculate and print the number of
seconds remaining in the day.
- 6.
- Make the program calculate and print the percentage of
the day that has passed.
- 7.
- Again, test your program by typing in a different time.
- 8.
- Again, add comments to the program, print it, and write
your name in the upper-right corner. Staple the two programs
together and turn them in!
HINT: you may want to use additional variables to hold values
temporarily during the computation. Variables like this, that
are used in a computation but never printed, are sometimes called
intermediate or temporary variables.
Next: About this document ...
Up: Homework 2: Variables and
Previous: Printing dates
Allen B. Downey
1999-02-10