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 480

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 480

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
 
cs190c/lab1_09.txt · Last modified: 2009/02/05 02:35 by tang
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki