math.ceil returns float (1.5)

188 views Asked by At

I need a ceil of a float which it doesn't give to me! Here is the part of the code:

    ne = j + e
    nk = ne / 6
    int(math.ceil (nk))
    p2 = nk * 11
    if p2 < p1:
        p1 = p2
    print (p2)

j, e and p1 already have values (in this case 4, 5 and 22) and yes, I imported math.

I can't see the problem and I have a few similar lines of code which work. Here it works:

    p2 = ne / 6
    int(math.ceil(p2))
    p2 = p2 * 11
    p2 = p2 + (nk * 3.5)
    nk = nj * 11
    p2 = p2 + nj
    nj = j - nn
    p2 = p2 + (nj*2.5)
    print (p2)

ne in this case is 6

1

There are 1 answers

1
Matteo Italia On

ceil doesn't change the value you passed (it cannot - float values are immutable); instead, it returns the elaborated value - that you are discarding, as you aren't assigning it to anything. You want something like

nk = int(math.ceil (nk))

and I have a few similar lines of code which work.

Check better; that cannot possibly work.