I have a simple python program
After the division, it shows the end value but I want to not show the .01
from __future__ import division
number = int(133)
output = float(0)
divideNumber = int(1)
stop = false
while stop == false
halfNumber = number / 2
output = number / divideNumber
output = round(output, 2)
if ".0" in str(output):
if "0.1" in str(output) or "0.2" in str(output ) or.... "0.9" in str(output):
#Do Nothing
else:
#Do Nothing
else:
print str(number) + " / " + divideNumber + " = "str(output)
divideNumber += 1
if divideNumber < halfNumber:
break
else:
#Do Nothing
print "Goodbye"
if I run it, this is the result:
133 / 1 = 133.0
133 / 7 = 19.0
133 / 11 = 12.09
133 / 12 = 11.08
133 / 19 = 7.0
133 / 22 = 6.05
133 / 33 = 4.03
133 / 43 = 3.09
133 / 44 = 3.02
133 / 64 = 2.08
133 / 65 = 2.05
133 / 66 = 2.02
Goodbye
My expected result is
133 / 1 = 133.0
133 / 7 = 19.0
133 / 19 = 7.0
Goodbye
Is my “if” statement wrong? I did not receive any errors!
If I got you right, you need to skip all numbers with non-round numbers. This check should be something like: