CPSC 115L: Introduction to Computing Fall 2010

Homework 2

CPSC 115-01: due Monday, September 20
CPSC 115-02: due Tuesday, September 21

1. Using Python as a calculator

Using DrPython's interactive mode, complete Exercise 4 (1), (2) in Chapter 2 of Downey. Upon completing each part of this exercise, save your interactive session.

2. What time will I get home?

Design and implement a Python script to solve the following generalization of Exercise 4 (3) in Chapter 2 of Downey: Given a start time and the number of miles I will run at tempo, 7 minutes and 12 seconds per mile, determine the time I will get home. As in Exercise 4 (3), assume that I will run the first and last miles at an easy pace of 8 minutes and 15 seconds per mile. You may also assume that the start and end times are in the morning. Your script should behave as follows:
Enter the hour of the start time: 6
Enter the minute of the start time: 52
Enter the number of miles I will run at tempo: 2
If I start at 6 : 52 AM and run 2 miles at tempo, then I will be home at 7 : 22 : 54 AM.
For values < 10, there is no need to print the leading zeros. As before, first write down your I/O specification and algorithm in pseudocode. Then implement your algorithm in a Python script named run.py. Run your script with five test cases, and save the snapshots of your test runs in a text file named run.out. As done in laboratories, put a file header at the top of each file.

3. Invoking functions

Using DrPython's interactive mode, express the following integers in the binary notation by invoking an appropriate function from the list of Built-in Functions in the Python Standard Library.
115
1823
2010
1048576
1048575
The hexadecimal notation, whose base is 16, is another common way to represent numbers in computing. In this notation, there are 16 possible values for a single digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Repeat the above exercise to express the given integers in the hexadecimal notation.

What to hand in

Submit the following in paper:

Plagiarism and academic dishonesty

Please remember our course policy on plagiarism and academic dishonesty: You are encouraged to consult with one another when you work on homework assignments, but in the end everyone must do one's own work to hand in. In particular, discussion of homework assignments should be limited to brainstorming and verbally going through strategies, but it must not involve one student sharing written solutions with another student. In the end everyone must write up solutions independently. If you have discussed with classmates or used any outside source, you must clearly indicate so on your solutions and provide all references. Turning in another person's work under your name is plagiarism and qualifies as academic dishonesty. Academic dishonesty is a serious intellectual violation, and the consequences can be severe. For more details, read the Student Handbook 2010–2011, pp. 21–29.


* CPSC 115L home page
Valid HTML 4.01!