In: Computer Science
Write a Python program to find the smallest positive integer that is a perfect square and it contains exactly three different digits.
I hve calculated square of a number from digit 1. I have converted number to list of digits(i.e. 445 will converted into ['4','4','5']) and than checked if list is having 3 elements.After it I have applied set opration on that list to have unique elements in list.If set operation is having 3 elements it means it is perfect square with 3 different digits so I have printed it.
number = 1 #check from number 1
while(1):
square = number * number #calculate square
string_number_list = []
string_number_list[:0] = str(square) #convert number to list of digits
if(len(string_number_list) == 3): #check if lengh of list is 3
if(len(set(string_number_list)) == 3): #Having all unique elements present
print("".join(string_number_list))
break
number = number + 1
Output screenshot: