CS21 Homework

 

Homework #1: Warmup Programs

Due 11:59pm Tuesday, September 11

This homework will require you to write some basic programs in python. You should save your programs in your cs21/homework/01 directory. A skeleton version of each program you will write will appear in cs21/homework/01 if you run update21. The program handin21 will only submit files in this directory.

Your programs are graded on both correctness and style. Please review the comments regarding programming style on the main page.

Email bio

Email me a brief biography of yourself. You can simply reply to my email I sent you, or find my email address at the top of my home page. Your bio should include your preferred name, a description of any prior programming or linux experience (none is completely ok), your major or possible intended majors, and any extra-curricular activities you would like to mention.

Birth year
In the current homework directory, edit the file birthyear.py to create a program that does the following:
This program determines your birth year
given your age and current year

Enter your age: 20
Enter the current year: 2006

You were either born in 1986 or 1985
Temperature Conversion
Edit the file tempconvert.py in the current homework directory to convert a given Fahrenheit temperature to Celsius. The formula to convert is C=5/9(F-32). Test your program with a few different values to make sure it works properly.
This program prints the Celsius temperature
given a Fahrenheit temperature.

Enter a Fahrenheit temperature: 70
70 degrees F is 21.11 degrees C
Text Pyramids
Edit the file triangle.py in the current homework directory to create a program that produces the following output:
This program prints an increasing series of right-justified stars

Enter desired number of lines: 7
      *
     **
    ***
   ****
  *****
 ******
*******
HINT: You can use the string " " to represent one blank space. Also think about how the number of spaces you want per line and the number of stars you want per line relate to your loop variable.

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, and only the most recent submission will be recorded. This is useful if you realize after handing in some programs that you'd like to make a few more changes to them.