Description
Write a program named strike.py that estimates the distance in miles to a lightning strike based on the elapsed time between the lightning and the sound of the thunder. Use the conversion factors that sound travels 1100 feet per second and one mile is 5280 feet. Sample run:
Enter time between lightning flash and thunder: 6 The lightning was 1.25 miles away.
Write a program named population.py that estimates the current population based on the fact that someone is born every 8 seconds, someone dies every 14 seconds, and one immigrant comes to the U.S. every 46 seconds. Assume the current population is 314,254,374, that a year is 365.25 days, there are 24 hours in a day, that an hour is 60 minutes, and a minute is 60 seconds. Do not use a loop to do the calculations. The input should be the number of years in the future and the output should be the estimated population in that many years. Sample run:
Enter number of years: 6
The estimated population in 6 years is 328514096
Write a program named invest.py to solve chapter 2 programming exercise #6. For each year, you are to add the annual amount to be invested each year to the current total and then apply interest to that full amount. Make certain your inputs are in the order specified in the problem. Output the current value of the investment after each year. Sample run:
Enter annual amount invested in IRA: 5000
Enter interest rate (e.g., 0.05 for 5%): 0.08 Enter number of years: 10 year, value 1 , 5400.0
- , 11232.0
- , 17530.56
- , 24333.004800000002
- , 31679.645184000005
- , 39614.01679872001
- , 48183.138142617616
- , 57437.78919402703
- , 67432.8123295492
- , 78227.43731591314
Use descriptive variable names and comment your code, including putting your name and class time at the top of the file in comments. See the rubric on iLearn for how your lab will be graded.
Test both your programs with a couple different inputs to be certain they are working correctly. After you have commented and tested your code, submit your programs by emailing them to [email protected] as attachments (send one email with three attachments) with the appropriate subject line. You must use Capital’s webmail as some email systems send attachments differently and I automatically extract the attachment based on the email address. Use the subject CS160-1ATT for the 1PM section and CS160-2ATT for the 2PM section.
1