Simple Math... not simple in Python?
Posted on Jan 08, 2009 under xn--zqqs84h3is.com | editv = 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:
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
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.
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.
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!
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.# |