import math
def perfectSquare(num):
if(math.ceil(math.sqrt(num)) == math.floor(math.sqrt(num))):
return True
else:
return False
list1 = [0,1]
list2 = []
for i in list1:
if perfectSquare(i):
list2.append(i)
list1.remove(i)
print(list2)
Here I am trying to generate a new list (list2) that will contain only perfect squares from available list list1. I am stuck since yesterday how to update it to [0,1]. I am getting only [0] as my output. ! is also a perfect square and it is not getting added.