0

I am taking in the values from a manifest.json file, the ranges of a variable as (4, 4.4, 0.1). This has 5 values now. In my code, I am trying to append these 5 values into a list but when I print the list, the decimal places are a little messed up

    def frange(start, end, step):
        tmp = start
        while(tmp <= end):
            yield tmp
            tmp += step


    core_er_val = make_tuple(config_vars['core_er_val'])
    core_er = (core_er_val[0], core_er_val[1])

    for i in frange(core_er_val[0], core_er_val[1], core_er_val[2]):
        print i
        core_er_list.append(i)
    print core_er_list

So now if i print i, I get:

4 4.1 4.2 4.3 4.4

But when I print core_er_list, I end up getting:

[4, 4.1, 4.199999999999999, 4.299999999999999, 4.399999999999999]

Is there someway I can fix this as later on when I try to compare the value with the index:

indexval = core_er_list.index(core_er)

I get an error saying that the element is not found.

Potato
  • 111
  • 10

0 Answers0