When using a for loop, for example:
def num_count(x):
for numbers in x:
if “numbers” is not always an integer, perhaps a float, how do you get by this? It throws an error.
is the only proper way to do this?
def num_count(x):
numbers = (int(x))
for i in numbers:
@xyphoris,
import math
def num_count(numbers):
print "floor\t int\t i\t ceil"
print "=====\t=====\t=====\t====="
for i in numbers:
print "{0}\t{1}\t{2}\t{3}".format(
math.floor(i),int(i),i,math.ceil(i))
num_count([0.12,1.6,1.4,-3.6])
gives the [output]
floor int i ceil
===== ===== ===== =====
0.0 0 0.12 1.0
1.0 1 1.6 2.0
1.0 1 1.4 2.0
-4.0 -4 -3.6 -3.0
http://stackoverflow.com/questions/31036098/what-is-the-difference-between-int-and-floor-in-python-3