Strict Standards: Declaration of Doku_Renderer_metadata::table_open() should be compatible with Doku_Renderer::table_open($maxcols = NULL, $numrows = NULL, $pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 24

Strict Standards: Declaration of Doku_Renderer_metadata::table_close() should be compatible with Doku_Renderer::table_close($pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /home2/cp-wiki/htdocs/inc/parser/metadata.php:24) in /home2/cp-wiki/htdocs/inc/actions.php on line 581

Warning: Cannot modify header information - headers already sent by (output started at /home2/cp-wiki/htdocs/inc/parser/metadata.php:24) in /home2/cp-wiki/htdocs/inc/actions.php on line 581
cs190c:lab1_09
Table of Contents

CS 190C, Lab 1: January 16, 2009

Links of Interest

Discussed Programs

principal = input("Principal: ")
rate = input("Annual percentage rate: ")
for year in range(10):
    principal = principal * (1+rate)
print principal
n = input("How many numbers? ")
avg = 0
for i in range(n):
    x = float(input("Enter next number: "))
    avg = avg + x/float(n)
print avg

In-Lab Problems

Convert and print a range of temperatures from degrees Fahrenheit to degrees Celsius. The formula to do so is tempC = (5/9)*(tempF - 32). Do this for the following ranges (inclusive for both min/max):

  1. Every degree from -20 through 32
  2. Every ninth degree from 5 through 212
  3. Every other degree from 80 to 30 (it must print the higher values first)

You should print the degrees in Fahrenheit and degrees Celsius for each requested value.

Solution

print 'Degrees F\tDegrees C'
for degF in range(-20, 33):
    degC = (degF - 32) / 1.8
    print degF, '\t\t', degC
for degF in range(5, 213, 9):
    degC = (degF - 32) / 1.8
    print degF, '\t\t', degC
for degF in range(80, 30, -2):
    degC = (degF - 32) / 1.8
    print degF, '\t\t', degC