This lab assignment requires you to write a few python programs. First, run update21. This will create the cs21/labs/01 directory and copy over any starting-point files for your programs. Next, move into your cs21/labs/01 directory and begin working on the python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.
$ update21 $ cd cs21/labs/01 $ pwd /home/your_user_name/cs21/labs/01We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!
As you write your first programs, start using good programming practices now:
Due to it's smaller mass, your weight on the Moon is about 1/6th your weight on the Earth. Edit a file called moonweight.py in the cs21/labs/01 directory and write a program to convert a weight given in pounds to what that weight would be on the Moon. Here are some sample runs of such a program:
$ python moonweight.py This program calculates what you would weigh on the moon. Please enter your weight on the Earth. Earth weight (lbs): 600 On the Moon, you would weigh 100.0 lbs $ python moonweight.py This program calculates what you would weigh on the moon. Please enter your weight on the Earth. Earth weight (lbs): 165 On the Moon, you would weigh 27.5 lbs $ python moonweight.py This program calculates what you would weigh on the moon. Please enter your weight on the Earth. Earth weight (lbs): 100 On the Moon, you would weigh 16.6666666667 lbs
Note: extra challenges are just for fun (i.e., no bonus points). Please only attempt them after completing your regular assignment.
See Your Weight On Other Planets for what you would weigh on the other planets in the solar system. Add a few other planets to your above program.
Earth weight (lbs): 100 On the Moon, you would weigh 16.6666666667 lbs On Jupiter, you would weigh 236.4 lbs On Mars, you would weigh 37.7 lbs
Write a program called windchill.py to calculate the wind chill, using the following formula:
$windchill = 35.74 + (0.6215*T) - 35.75*(W^{0.16}) + 0.4275*T*(W^{0.16})$
where $T$ is the temperature in degrees Fahrenheit, and $W$ is the wind speed in miles-per-hour.
$ python windchill.py This program calculates the 'wind chill', given the temperature (F) and the wind speed (mph). Temperature (F): 20 Wind Speed (mph): 15 What the temperature feels like: 6.21888526608 F
Write a program called stairs.py that asks the user for some text and a number, and then displays the text in the terminal window with a stair-like effect.
Here is a sample run, showing how your program should work.
$ python stairs.py text: Hello, Swarthmore!! n: 10 Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!! Hello, Swarthmore!!
Many running coaches advise no more than a 10% increase in mileage each week. For example, if you run a total of 10 miles this week, next week you should not run more than 11 miles in total.
Write a program that asks the user for their current running mileage, and then displays a 16-week program that increases their mileage by 10% each week.
$ python mileage.py Current Weekly Mileage: 10 Week 1: 11.0 Week 2: 12.1 Week 3: 13.31 Week 4: 14.641 Week 5: 16.1051 Week 6: 17.71561 Week 7: 19.487171 Week 8: 21.4358881 Week 9: 23.57947691 Week 10: 25.937424601 Week 11: 28.5311670611 Week 12: 31.3842837672 Week 13: 34.5227121439 Week 14: 37.9749833583 Week 15: 41.7724816942 Week 16: 45.9497298636
Use print formatting to clean up the above 16-week table, like this:
Week 1: 11.0 Week 2: 12.1 Week 3: 13.3 Week 4: 14.6 Week 5: 16.1 Week 6: 17.7 Week 7: 19.5 Week 8: 21.4 Week 9: 23.6 Week 10: 25.9 Week 11: 28.5 Week 12: 31.4 Week 13: 34.5 Week 14: 38.0 Week 15: 41.8 Week 16: 45.9
Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.