Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For vs while loop

Hi there! I am new to sageMath and I´m trying to solve a certain exercise with my buddy, the thing is that we need a list of perfect squares and I though that I could do it this way

n =95        
squares=[]  
edges=[];
for i in range(int(sqrt(n)+1)):  
    cuadrados.append(i*i)

Then @tmonteil told me that it would be a good idea to use the while loop because I am interating until the int(sqrt(n)+1)condition is no longer true which make sense to me, therefore this would be what I think is equivalent.

n =95      
squares=[]  
edges=[]
i=0
root= int(sqrt(n)+1)
while i < root:  
    cuadrados.append(i*i)

however I keep getting this Traceback (most recent call last) in different parts of the code, and I don't really know why, any help will be much I appreciated

For vs while loop

Hi there! I am new to sageMath and I´m trying to solve a certain exercise with my buddy, the thing is that we need a list of perfect squares and I though that I could do it this way

n =95        
squares=[]  
edges=[];
for i in range(int(sqrt(n)+1)):  
    cuadrados.append(i*i)
squares.append(i*i)

Then @tmonteil told me that it would be a good idea to use the while loop because I am interating until the int(sqrt(n)+1)condition is no longer true which make sense to me, therefore this would be what I think is equivalent.

n =95      
squares=[]  
edges=[]
i=0
root= int(sqrt(n)+1)
while i < root:  
    cuadrados.append(i*i)
squares.append(i*i)

however I keep getting this Traceback (most recent call last) in different parts of the code, and I don't really know why, any help will be much I appreciated