Simple Math... not simple in Python?

Posted on Jan 08, 2009 under xn--zqqs84h3is.com | edit
  • i have a simple way in vb to convert any number into a integer multiple of 10

    v = int(v/10)*10

    but this does not work in python.

    the error tells me that the '/' is not allowed.

    so i tried int((v/10)) but no workie.

    help please!

    :nuts:


  • ok, maybe it is a string conversion thing, i'm not sure. in vb it is a variant so it does not matter. but python is much more picky... it is getting on my nerves actually.

    goal: input a number, do some math, output a string using the math's output.

    when i try it on xbmc i get this log...


    info typeerror
    info :
    info unsupported operand type(s) for /: 'str' and 'int'


    def getdimlevel(type, v): # types: 1=image, 2=text
    if type == 1:
    v = "dims" & str(int(v/10)*10) & ".gif"
    elif type == 2:
    v = str(int(v/10)*10) & "%"
    return v


  • it is saying that you can't divide a str by and int.
    the parameter you are passing in for v is a str.
    if v is something like '100' (a string that looks like a number) do

    v = "dims" + str(int(parseint(v)/10)*10) + ".gif"

    i don't know what & does to strings but you probably want + instead.


  • haha sorry i was thinking javascript.

    v = "dims" + str((int(v)/10)*10) + ".gif"
    will be fine. no need to cast the division back into an int since this is integer arithmetic.


  • it is saying that you can't divide a str by and int.
    the parameter you are passing in for v is a str.
    if v is something like '100' (a string that looks like a number) do

    v = "dims" + str(int(parseint(v)/10)*10) + ".gif"

    i don't know what & does to strings but you probably want + instead.
    parseint does not seem to be valid?

    the goal is to take a number, change it to the 'closest' multiple of 10, then create a filename with it.

    example:

    input = integer 43
    closest multiple of 10 = 40
    create filename = dims40.gif

    in vb this is so simple, python wants to make it difficult!


  • / is correct for division.

    maybe your indentation might be off or maybe v isn't declared before the formula.

    should work fine.

    i just did the following and works fine.

    v = 1034
    v = int(v/10)*10
    print v

    result = 1030







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Simple Math... not simple in Python? , Please add it free.