CS21 Lab 1: First programs

Due before Midnight Saturday 14 September 2013

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. Alpaca Sweaters

The wool gathered from shearing a typical alpaca fleece weighs about three pounds and can be spun into roughly 1900 yards of yarn. Knitting an adult sweater requires about 975 yards of yarn. Write a program called alpaca.py that prompts the user to enter a number of alpacas fleeces are available and computes the number of full sweaters you could knit from the fleeces.

Here are some sample runs of such a program:

$ python alpaca.py

How many alpacas do you have?: 1

You could make 1 sweaters from 1 alpacas

$ python alpaca.py

How many alpacas do you have?: 2

You could make 3 sweaters from 2 alpacas

$ python alpaca.py

How many alpacas do you have?: 4

You could make 7 sweaters from 4 alpacas

Start knitting after you finish your python assignment
2. Crop Yield
A rough estimate of corn yield per acre of farmland is 180 bushels/acre. Write a program called cropyield.py that prints a table of acreage and crop yield. Your program should prompt the user for the maximum number of acres in the table. Your table should start at 5 acres and go up to the maximum number of acres in steps of 5 acres. You may assume the user enters a number of acres that is a multiple of five. Your table should have a header for each column as shown in the examples below

Here are some sample runs of such a program:

 
$ python cropyield.py

Enter maximum number of acres: 20

 acres  bushels
---------------
   5        900
  10       1800
  15       2700
  20       3600

$ python cropyield.py

Enter maximum number of acres: 45

 acres  bushels
---------------
   5        900
  10       1800
  15       2700
  20       3600
  25       4500
  30       5400
  35       6300
  40       7200
  45       8100

For the overly curious, consult a college of agriculture for better corn yield estimators starting from kernels per ear.
3. Cost of Breakfast

Here's a conversion table for cost of common breakfast items from the Bureau of Labor Statistics consumer price index.

Write a program called breakfast.py that asks the user for the quantity of these three items and computes the total cost.

Here are some sample runs of such a program:

$ python breakfast.py

How many dozens of eggs? 1
How many gallons of milk? 1
How many pounds of bananas? 2

Your total cost for these items would be $6.50

$ python breakfast.py

How many dozens of eggs? 1
How many gallons of milk? 0
How many pounds of bananas? 10

Your total cost for these items would be $7.88


Submit

Once you are satisfied with your programs, hand them in by typing handin21 at the unix 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