How can I set a range for a float?

0

Trying to implement Newton's method to find roots in polynomials using Horner's method.

n=len(a)-1

print("k\t  a\t x\t  px")
for k in range (0, iterMax):
    b=a[0] 
    c=b
    for i in range (n-1,1):
        b=a[i]+(b*x)
        c=x*c+b
    b=b*x+a[n]   
    if x in range of (-epsilon, epsilon)
        print ("raiz encontrada")

on the line

  

if x in range of (epsilon, epsilon)

The compiler warns that "'float' object can not be interpreted as an integer"

    
asked by anonymous 29.09.2017 / 22:17

1 answer

0

It makes no sense for you to make a fork with float numbers, so you should rent it.

Use the round method.

Example:

round(3.2)

Output:

3

If you really need to work with float numbers in a range, use the While loop as long as the condition is not found.

But in your case, you're just asking if a number is in a domain, I suggest you do it here:

n=len(a)-1

print("k\t  a\t x\t  px")
for k in range (0, iterMax):
    b=a[0] 
    c=b
    for i in range (n-1,1):
        b=a[i]+(b*x)
        c=x*c+b
    b=b*x+a[n]   
    if (x>=(-epsilon) and x<=(epsilon)): # Aqui foi feita a mudança.
        print ("raiz encontrada")
    
29.09.2017 / 22:21