Use the command line to create a new directory called lab4 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.
You might think that running has very little to do with Computer Science. However, there are a lot of useful computations we can do to help a runner figure out how fast they ran. Race distances are typically given in kilometers: 5k, 10k, etc. A fast runner might run a 5K in 20 minutes, but the winning time is usually closer to 15 minutes. In the US, runners typically measure their pace in minutes per mile. We will write a program to perform these computations.
Details
In Emacs, create a Python program in a file called runner.py. Your program should have variables that store:
- the distance of the race in kilometers
- the minutes part of their finish time
- the seconds part of their finish time
Your program should then compute and print the users pace in minutes per mile. Make sure you use proper variable names, formats the output nicely, and follow the courses code conventions.
Example
$ python3 runner.py If you run a 5 kilometer race in 27 minutes and 15 seconds, your pace will be 8.72 minutes per mile.
Hint
Challenge
Many runners set goals to improve their pace. Add to your program a variable for the user to store their desired minutes per mile into. Compute how quickly they would have to run the race, and print this value as well.
Voyager 1 is a space probe that was launched by NASA in 1977. It is currently the farthest man-made object from Earth. It is very likely that Voyager 1 is (or will be) the first man-made object to exit the solar system. Currently, Voyager 1 is approximately 19,279,655,290 km from Earth. The Voyager 1 communicates with radio waves, which travel at the speed of light, 299,792,458 m/s. At such a great distance, communications take an appreciable amount of time to reach earth. And yet, Voyager 1 is still closer to the Sun than any other star in our galaxy.
Details
In Emacs create a Python program in a file called voyager.py. The program should print how long it takes a signal from Voyager 1 to reach the Earth and how long it would take Voyager 1 to reach Proxima Centauri at its current velocity. The Voyager 1's velocity is 61,400 km/h. Proxima Centauri is 4.2 light years from Earth. These calculation should be performed using Python's arithmetic operations and printed nicely labeled and formatted. Be sure to use variables where appropriate, and follow the course code conventions.
Example
$ python3 voyager.py It takes 64310.00772541116 seconds for a message from Voyager to reach Earth. It will take 73789.26858417667 years for Voyager to reach Proxima Centauri.
Hint
Challenge
Voyager gets its power through the radioactive decay of
. It is estimated that Voyager loses about 0.79% of its power output per year. Using a slightly modified version of the compound interest formula, compute how many years Voyager could maintain power using the built in power supply.power\_end = start\_power \times (1 - decay\_rate) ^ {time}
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.