Question

In: Computer Science

Write a Python program to find the smallest positive integer that is a perfect square and...

Write a Python program to find the smallest positive integer that is a perfect square and it contains exactly three different digits.

Solutions

Expert Solution

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:


Related Solutions

C program //In this assignment, we will find the smallest positive integer that // can be...
C program //In this assignment, we will find the smallest positive integer that // can be expressed as a sum of two positive cube numbers in two distinct ways. // More specifically, we want to find the smallest n such that n == i1*i1*i1 + j1*j1*j1, // n == i2*i2*i2 + j2*j2*j2, and (i1, j1) and (i2, j2) are not the same in the sense that // not only (i1, j1) not euqal to (i2, j2), but also (i1, j1)...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie Germain prime that is greater or equal to n.
In Python, write a program to get a positive integer n from keyboard first (your program...
In Python, write a program to get a positive integer n from keyboard first (your program must be able to check the validation of n being positive), and then get n integers from keyboard and store these n integers in a list. Do some processing, and print out average of the elements in the list at end of your program. For example, suppose user enters 3 first (n = 3), which means we get another three integers from the user....
Write following program using Python: A positive integer greater than 1 is said to be prime...
Write following program using Python: A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that asks the user to enter a integer greater than 1, then displays all of the prime numbers that are less than or equal to the number entered. Last, create two files. One file will hold all of...
Find the smallest positive integer x that satisfies the system of congruences x ≡ 3 (mod...
Find the smallest positive integer x that satisfies the system of congruences x ≡ 3 (mod 5). x ≡ 5 (mod 7). x ≡ 7 (mod 11)
(Python) Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:
In Python8.21 Program: Convert to binary. Sections 2.7, 3.8, 5.2. Functions.Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:As long as x is greater than 0    Output x % 2 (remainder is either 0 or 1)    x = x // 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string.Your program must define and call the following two functions. The function integer_to_reverse_binary() should return...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT