Reputation: 13
In the code below,
abc = (1,2,3)
a = abc[0]
b = abc[1]
c = abc[2]
print('%d, %d, %d' %(a,b,c)) # gives 1,2,3 as expected
a /= 3
b /= 3
c /= 3
print('%d, %d, %d' %(a,b,c)) # gives 0,0,1... which is NOT expected
I'm trying, however, to have a, b, c
be 0.333, 0.6666, 1
respectively.
This problem persists even when I:
even when I cast everything into a float like:
a = float(float(a)/float(3.0)) # still returns 0
I'm even using python 3, so an int/int division should return a float regardless.
Upvotes: 1
Views: 197
Reputation: 180441
You are using %d
so the output is printed as ints/decimal just use print:
print(a,b,c)
Upvotes: 1
Reputation: 49803
Your print
statements say to display the values as integers (%d
); try using %f
instead.
Upvotes: 9