# Pretty-print a float with only two decimal places

x = 162.0/7.0  # Make a float with something after the decimal point
strIn = str(x) # Get Python's string representation of the number

i = 0        # Integer variable to hold index into strIn
strOut = ""  # Output string
end = len(strIn)  # Integer variable that will ultimately be the length of 
                  # strOut; but since we don't know how long it will be
                  # yet, set this to be length of strIn (our first guess).
while i < end:    
    if i>= len(strIn):   # No more digits in strIn
        char = "0"       # We'll add the digit zero to strOut
    else:                # Still have digits in strIn
        char = strIn[i]  # Get the digit (a one-char string)
    if char == ".":      # Is this the decimal point?
        end = i+3        # If so, strOut should include this plus two 
                         # decimal places. 
    strOut = strOut+char # Add new digit to strOut
    print strOut         # Print to make sure things are going OK
    i = i+1              # Next digit
    




