This shows you the differences between two versions of the page.

Both sides previous revision Previous revision | |||

cs190c:problemset1 [2008/01/11 15:45] jtk |
cs190c:problemset1 [2008/01/11 15:46] (current) jtk |
||
---|---|---|---|

Line 31: | Line 31: | ||

- | ==== Problem 1 ==== | + | ===== Problem 1 ===== |

During a thunderstorm when lightning strikes, you often hear the thunder some time after you see the flash. However, if you know the speed of light and sound, you can figure out how far away the lightning strike was based upon the amount of time you heard the bang after you heard the flash. For our purposes, since light is so much faster than sound (especially over a distance of a few miles), we assume that the light is visible the instant of the lightning strike. Thus, if we know the speed of sound, we can calculate the distance to the strike. Your program should do the following: | During a thunderstorm when lightning strikes, you often hear the thunder some time after you see the flash. However, if you know the speed of light and sound, you can figure out how far away the lightning strike was based upon the amount of time you heard the bang after you heard the flash. For our purposes, since light is so much faster than sound (especially over a distance of a few miles), we assume that the light is visible the instant of the lightning strike. Thus, if we know the speed of sound, we can calculate the distance to the strike. Your program should do the following: | ||

Line 46: | Line 46: | ||

- | ==== Problem 2 ==== | + | ===== Problem 2 ===== |

A ball is dropped from the roof of a tall building. Assume that the ball starts at rest, and that the drop is exactly the height of the building. Given the amount of time the ball takes to contact the ground, calculate how high the building is. | A ball is dropped from the roof of a tall building. Assume that the ball starts at rest, and that the drop is exactly the height of the building. Given the amount of time the ball takes to contact the ground, calculate how high the building is. | ||

Line 59: | Line 59: | ||

- | ==== Problem 3 ==== | + | ===== Problem 3 ===== |

The user inputs the month (//m//), day (//d//), and year (//y//) of a date by being prompted with appropriate text. The output of your program is the day of the week for that date (//w//). For //m//, let 1=January, 2=February, etc. The year should be given with four digits (i.e., 2008, not 08). | The user inputs the month (//m//), day (//d//), and year (//y//) of a date by being prompted with appropriate text. The output of your program is the day of the week for that date (//w//). For //m//, let 1=January, 2=February, etc. The year should be given with four digits (i.e., 2008, not 08). | ||

Line 73: | Line 73: | ||

- | ==== Problem 4 ==== | + | ===== Problem 4 ===== |

Section 2.7 of Zelle (pages 42-45) develops and presents program futval.py, which computes the value of an investment. This problem extends the investment program so that (i) the number of years is a variable determined by the input and (ii) an additional yearly investment is made (it is the same for all years). | Section 2.7 of Zelle (pages 42-45) develops and presents program futval.py, which computes the value of an investment. This problem extends the investment program so that (i) the number of years is a variable determined by the input and (ii) an additional yearly investment is made (it is the same for all years). | ||

Line 88: | Line 88: | ||

- | ==== Problem 5 ==== | + | ===== Problem 5 ===== |

There exist a number of approximations of the value of pi. Two are listed below: the [[ http://en.wikipedia.org/wiki/Wallis_product | Wallis formula ]], and the Leibniz formula. Your program should approximate pi with the first k steps of the both approximations where k is given as input by the user. | There exist a number of approximations of the value of pi. Two are listed below: the [[ http://en.wikipedia.org/wiki/Wallis_product | Wallis formula ]], and the Leibniz formula. Your program should approximate pi with the first k steps of the both approximations where k is given as input by the user. | ||