Python to turn a number into an integer

Asked

Viewed 547 times

0

import math
x=9
raiz=math.sqrt(x)
print raiz
for i in range (raiz,9): #Problema aqui
 i=i**2
 print i

I need to create a for with the root of an operation (always whole. 2, 3,4,5...) but when I try to use the is the way I made the mistake. It says that the root has to be integer (python understands as 2.0 , 3.0 , etc.)?

1 answer

1

You need to convert the raiz for whole

import math
x=9
raiz=math.sqrt(x)
print(raiz)
for i in range (int(raiz),9): #Problema aqui
    i=i**2
    print(i)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.