Skip Navigation

I'm learning python and starting learning list comprehension. I though I would create a quick list from 1 to 50 in .1 increments to test logic etc and notice when I run the program the output is as sh

I'm learning python and starting learning list comprehension. I though I would create a quick list from 1 to 50 in .1 increments to test logic etc and notice when I run the program the output is as shown below. My question is why am I not just getting .3. Which would be the next number in the sequence

To get the output I want would I have to use a rounding function? Or limit the value to one place.

Thanks

[0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999, 1.2, 1.3, 1.4000000000000001, 1.5000000000000002, 1.6000000000000003, 1.7000000000000004, 1.8000000000000005, 1.9000000000000006, 2.0000000000000004, 2.100000000000000

count = 0
a = []
while count < 50.1:
a.append(count)
count = count + .1
print(a)

#python

1