Automorphic Number in PythonA number is said to be an automorphic number if the last digits of the square of this number give the same number. The following are the examples of automorphic numbers- 1. Input: 25 Output - Yes, it is an automorphic number. Reason - The square of 25 gives 625, since the last digits are 25 it is an automorphic number. 2. Input: 14 Output - No, it is not an automorphic number. Reason - The square of 14 gives 196, since the last digits are 96 it is not an automorphic number. 3. Input: 76 Output - Yes, it is an automorphic number. Reason - The square of 76 gives 6776, since the last digits are 76 it is an automorphic number. Since the concept is clear to us now, let us see how we can build the logic to check whether a number is automorphic or not. We know that the modulus operator can be used to perform functions on the digits of a number. The following illustrates how it can be done in Python. Example - Output Enter a number you want to check: 76 Yes, 76 is an automorphic number So, let's have a glance at the step-by-step approach of the same-
Let us see what happens when we pass the numbers that we discussed in the example. Since 25 is an automorphic number, it displays the required message. Output - 2 Enter a number you want to check: 25 Yes, 25 is an automorphic number Since 14 is not an automorphic number, it displays the required message. Output - 3 Enter a number you want to check: 14 No, 14 is not an automorphic number Using While loopThe next approach to do the same is as follows- Example - Output Enter the number you want to check: 25 Yes, it is an automorphic number. Let us understand the steps we have followed in this program-
So, in this article, we learned what an automorphic number is and how we can check whether a given number is automorphic or not using Python. Next Topicsizeof in Python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India