I need help with my code. Im kind of new to program and i need to do a final project for my class. I decided to do a converter program because i thought it would be sort of easy and challenging at the same time. but i wrote the program but its not working could someone help!!! Here is what i have can you see if im doing it write or what please.

def inches(start):
    convert_to = [["feet", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? feet, miles, millimeters, centimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 0.0833333       ## feet
    convert_to[1][1] = value * 0.000015783     ## miles
    convert_to[2][1] = value * 25.4            ## millimeters
    convert_to[3][1] = value * 2.54            ## centimeters
    convert_to[4][1] = value * 0.0254          ## meters
    convert_to[5][1] = value * 0.0000254       ## kilometers
    convert_to[6][1] = value * 0.0277778       ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards")
inches(start)

def feet(start):
     convert_to = [["inches", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, miles, millimeters, centimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 12.0           ## inches
    convert_to[1][1] = value * 0.000189394    ## miles
    convert_to[2][1] = value * 304.8          ## millimeters
    convert_to[3][1] = value * 30.48          ## centimeters
    convert_to[4][1] = value * 0.3048         ## meters
    convert_to[5][1] = value * 0.0003048      ## kilometers
    convert_to[6][1] = value * 0.333333       ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
feet(start)

def miles(start):
 convert_to = [["feet", 0], ["inches", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, millimeters, centimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 5280.0         ## feet
    convert_to[1][1] = value * 63360.0        ## inches
    convert_to[2][1] = value * 1609000.0      ## millimeters
    convert_to[3][1] = value * 160934.0       ## centimeters
    convert_to[4][1] = value * 1609.34        ## meters
    convert_to[5][1] = value * 1.60934        ## kilometers
    convert_to[6][1] = value * 1760.0         ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
miles(start)

def millimeters(start):
    convert_to = [["feet", 0], ["miles", 0], ["inches",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, miles, centimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 0.00328084      ## feet
    convert_to[1][1] = value * 0.00000062137   ## miles
    convert_to[2][1] = value * 0.0393701       ## inches
    convert_to[3][1] = value * 0.1             ## centimeters
    convert_to[4][1] = value * 0.001           ## meters
    convert_to[5][1] = value * 0.000001        ## kilometers
    convert_to[6][1] = value * 0.00109361      ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
millimeters(start)

def centimeters(start):
     convert_to = [["feet", 0], ["miles", 0], ["millimeters",0],
                  ["inches", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, miles, millimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 0.0328084      ## feet
    convert_to[1][1] = value * 0.0000062137   ## miles
    convert_to[2][1] = value * 10.0           ## millimeters
    convert_to[3][1] = value * 0.393701       ## inches
    convert_to[4][1] = value * 0.01           ## meters
    convert_to[5][1] = value * 0.00001        ## kilometers
    convert_to[6][1] = value * 0.0109361      ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
centimeters(start)

def meters(start):
    convert_to = [["feet", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["inches", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, miles, millimeters, centimeters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 3.28084        ## feet
    convert_to[1][1] = value * 0.000621371    ## miles
    convert_to[2][1] = value * 1000.0         ## millimeters
    convert_to[3][1] = value * 100.0          ## centimeters
    convert_to[4][1] = value * 39.3701        ## inches
    convert_to[5][1] = value * 0.001          ## kilometers
    convert_to[6][1] = value * 1.09361        ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
meters(start)

def kilometers(start):
     convert_to = [["feet", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["inches", 0], ["yards",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, miles, millimeters, centimeters, meters, yards ")
    value = input("Value? ")
    convert_to[0][1] = value * 3280.84         ## feet
    convert_to[1][1] = value * 0.621371        ## miles
    convert_to[2][1] = value * 1000000.0       ## millimeters
    convert_to[3][1] = value * 100000.0        ## centimeters
    convert_to[4][1] = value * 1000.0          ## meters
    convert_to[5][1] = value * 39370.1         ## inches
    convert_to[6][1] = value * 1093.61         ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards")
kilometers(start)

def yards(start)
 convert_to = [["feet", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["inches",0]]
    for item in convert_to:
        print item[0]
    end = raw_input("Convert to? inches, feet, miles, millimeters, centimeters, meters, kilometers")
    value = input("Value? ")
    convert_to[0][1] = value * 3.0             ## feet
    convert_to[1][1] = value * 0.000568182     ## miles
    convert_to[2][1] = value * 914.4           ## millimeters
    convert_to[3][1] = value * 91.44           ## centimeters
    convert_to[4][1] = value * 0.9144          ## meters
    convert_to[5][1] = value * 0.0009144       ## kilometers
    convert_to[6][1] = value * 36.0            ## inches
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards")
yards(start)

the error is shown after for item in convert_to:

def feet(start):
     convert_to = [["inches", 0], ["miles", 0], ["millimeters",0],
                  ["centimeters", 0], ["meters", 0], ["kilometers", 0], ["yards",0]]
    for item in convert_to:### unindent does not match any outer indentation level###
        print item[0]
    end = raw_input("Convert to? inches, miles, millimeters, centimeters, meters, kilometers, yards")
    value = input("Value? ")
    convert_to[0][1] = value * 12.0           ## inches
    convert_to[1][1] = value * 0.000189394    ## miles
    convert_to[2][1] = value * 304.8          ## millimeters
    convert_to[3][1] = value * 30.48          ## centimeters
    convert_to[4][1] = value * 0.3048         ## meters
    convert_to[5][1] = value * 0.0003048      ## kilometers
    convert_to[6][1] = value * 0.333333       ## yards
    for item in convert_to:
        if end == item[0]:
            print "%s to %s, %7.2f = %7.2f" % (start, end, value, item[1])
start = raw_input ("Convert from? inches, feet, miles, millimeters, centimeters, meters, kilometers, yards ")
feet(start)

Edited 4 Years Ago by tizzqman

Check the line indentations up to and including that point. Also, you only want one input function instead of one in each function. You then test for the input and call the appropriate function. You can write one function to convert anything to one common measure, say millimeters for example since it is the smallest unit. You then convert the millimeters to whatever the end measure is, so convert_to_miles() for example will know that it is receiving millimeters and would only have one calculation to convert millimeters to miles.

## an example of one input function
measure=['', 'inches', 'feet', 'miles', 'millimeters', 'centimeters', 'meters', \
                 'kilometers', "yards"]
start = -1
while start > 8 or start < 1:
    for ctr in range(1, 9):
        print ctr, measure[ctr]

    start = raw_input ("Enter a number for conversion from ")
    start = int(start)

end = -1
while end > 8 or end < 1 or end == start:
    print
    for ctr in range(1, 9):
        if ctr != start:  ## eliminate start choice
            print ctr, measure[ctr]

    end = raw_input ("Enter a number to convert to ")
    end = int(end)

print "You chose %s to %s" % (measure[start], measure[end])

## assume miles to feet
if start == 3:
    ## convert everything to millimeters
    ret_mil = convert_to_millimeters(start, 'miles')
if end == 2:
    ret_value = convert_to_miles(ret_mil)

Edited 4 Years Ago by woooee

So I could do something like above but keep the classes I have and when I would select an option from the above code it would automatically bring up the class an do the conversion??? I'm kind of confused.

This article has been dead for over six months. Start a new discussion instead.