CS21 Lab 1: First programs

Due Saturday, Feb 1st 11:59pm

This lab assignment requires you to write three programs in python. First, run update21. This will create the cs21/labs/01 directory (if you haven't already) 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/01
We will only grade files submitted by handin21 in this labs directory, so make sure your programs are in this directory!

1. Pizza Party

You have been tasked with organizing a pizza party and you will use your Python skills to help you plan for it. Write a program called pizza.py that prompts the user to enter the number of pizzas they were planning on ordering. Assume each pizza has eight slices and each of your guest would like three slices of pizza. Your program will then print the maximum number guests that can attend your party and all be fed by the number of pizzas ordered.

Here are some sample runs of such a program:

$ python pizza.py

How many pizzas do you want to order? 10

With 10 pizzas, you can have 26 guests.

$ python pizza.py

How many pizzas do you want to order? 4

With 4 pizzas, you can have 10 guests.

$ python pizza.py

How many pizzas do you want to order? 13

With 13 pizzas, you can have 34 guests.
Have fun at the party (after you finish your python assignment)!

2. Windchill Factor
When the wind is blowing, it feels colder than the actual temperature due to the windchill effect. You will write a program windChill.py to generate a windchill table for a given temperature. Your table should start with a wind speed of 5 mph and go 50 mph in 5 mph increments. Your table should have a header for each column as shown in the examples below.

To help you out, we'll give you the python code to calculate the windchill. The code below assumes you have a variable temp which is the temperature in degrees Fahrenheit and a variable windSpeed which is the speed of the wind in miles per hour (mph).

windChill = 35.74 + 0.6215*temp - 35.75*windSpeed**0.16 + 0.4275*temp*windSpeed**0.16

The ** is not a typo, this is the Python way for raising one number to the power of another.

Here are some sample runs of such a program:

 
$ python windChill.py

What temperature would you like to compute a windchill chart for? 30

Here is a windchill chart for a temperature of 30.0 degrees:
Windspeed   Windchill
(mph)       (Fahrenheit)
------------------------
        5   24.7
       10   21.2
       15   19.0
       20   17.4
       25   16.0
       30   14.9
       35   13.9
       40   13.0
       45   12.2
       50   11.5

$ python windChill.py

What temperature would you like to compute a windchill chart for? 12

Here is a windchill chart for a temperature of 12.0 degrees:
Windspeed   Windchill
(mph)       (Fahrenheit)
------------------------
        5     3.6
       10    -1.1
       15    -4.0
       20    -6.3
       25    -8.0
       30    -9.6
       35   -10.9
       40   -12.1
       45   -13.1
       50   -14.1

Bundle up, it's cold outside!
3. Snowfall

Your last program will compute when it snows, how many gallons of water falls on Swarthmore's campus. Your program snowFall.py will ask the user to enter a snowfall total in inches and your program will print how many gallons of water has fallen on our campus. Let's walk through the conversions you'll need to compute this.

First we need to convert inches of snow to inches of water. The conversion ratio varies depending on the type of snow, but for this area an 8 to 1 ratio is typical, so 8 inches of snow is about the same as 1 inch of rain. That means if it snows 5 inches, it would be the equivalent of 5/8 or 0.625 inches of water on the ground.

Next, we need to determine the size of the campus in square inches. Swarthmore's campus is about 425 acres and one acre is 6,272,640 square inches. Multiply the two together to get the size of the campus in square inches. If we multiply the campus size by the amount of inches of water calculated above, we'll get the total water on the campus in cubic inches.

The last conversion we'll need is to convert from cubic inches of water to gallons. The conversion rate is 1 cubic inch equals 0.004329 gallons.

Here are some sample runs of such a program:

$ python snowFall.py

How many inches of snow has fallen? 8

8.0 inches of snow equals 11540559.9 gallons of water for Swarthmore's campus.

$ python snowFall.py

How many inches of snow has fallen? 3.5

3.5 inches of snow equals 5048995.0 gallons of water for Swarthmore's campus. 
Now, that's a lot of water!

Hacker's Challenge: Full Windchill Chart

This problem is an optional bonus problem. It is challenging and is not required, and you should not attempt it until you are completely finished with the other three lab problems. It will also not get you any extra points -- you will only be rewarded with extra knowledge and satisfaction. :)

Write a program called windChillChart.py that asks the user for four values: a max temperature, a min temperature, a min wind speed, and a max wind speed. Using the same windchill formula above, make a two dimensional windchill chart for the range of wind speeds and temperatures in five degree/mph increments. You can assume all the values entered by the user are multiples of 5. A sample chart for a wind speed of 5-25 and temperature for 35-10 is shown below. To save space, print the windchill as a whole number. Hint: you can have a for loop inside of another for loop. This is known as a nested for loop.

$ python windChillChart.py

This program will create a windchill chart for you.
Please answer the following questions.
Max temperature for chart? 40
Min temperature for chart? -15
Min wind speed for chart? 5
Max wind speed for chart? 60

           Temperature
 Wind |    40    35    30    25    20    15    10     5     0    -5   -10   -15
------+------------------------------------------------------------------------
    5 |    36    31    25    19    13     7     1    -5   -11   -16   -22   -28
   10 |    34    27    21    15     9     3    -4   -10   -16   -22   -28   -35
   15 |    32    25    19    13     6    -0    -7   -13   -19   -26   -32   -39
   20 |    30    24    17    11     4    -2    -9   -15   -22   -29   -35   -42
   25 |    29    23    16     9     3    -4   -11   -17   -24   -31   -37   -44
   30 |    28    22    15     8     1    -5   -12   -19   -26   -33   -39   -46
   35 |    28    21    14     7     0    -7   -14   -21   -27   -34   -41   -48
   40 |    27    20    13     6    -1    -8   -15   -22   -29   -36   -43   -50
   45 |    26    19    12     5    -2    -9   -16   -23   -30   -37   -44   -51
   50 |    26    19    12     4    -3   -10   -17   -24   -31   -38   -45   -52
   55 |    25    18    11     4    -3   -11   -18   -25   -32   -39   -46   -54
   60 |    25    17    10     3    -4   -11   -19   -26   -33   -40   -48   -55

Submit

Once you are satisfied with your programs, hand them in by typing handin21 at the Linux prompt.

You may run handin21 as many times as you like. We will grade the most recent submission submitted prior to the deadline

Remember: for this lab, programs must appear in your cs21/labs/01 directory. If you create your programs in a different directory, use the unix mv or cp commands to move or copy them into the cs21/labs/01 directory. For example:

 cp  myprog.py  ~/cs21/labs/01/myprog.py