![]() ![]() Code reusability increases as a function can be called multiple times.It simplifies the interface of the code.Functions help reduce the complexity of the code.Since the process is not terminating with 1 as the last single digit, 183 is not considered to be a magic numberįunction is a block of code that is executed when it is called. The sum of the digits of 12 is (1+2) = 3. The sum of the digits of 183 is (1+8+3) = 12. Since the process is not terminating with 1 as the last single digit, 12345 is not considered to be a magic number. The sum of the digits of 15 is (1+5) = 6. Since the process is terminating with 1 as the last single digit, 1234 is considered to be a magic number. The sum of the digits of 10 is (1+0) = 1. Since the process is terminating with 1 as the last single digit, 55 is considered to be a magic number. The sum of the digits of 55 is (5+5) = 10. Let us look at a few examples to understand what a Magic Number is:. If the digit left over is 1, then the original number is called a magic number. If we iterate the process of summing the digits of a number and then consider the sum as the new number, hence repeating the process till we are left with a single digit. We shall use functions in Python for the same. In this Python tutorial, we shall see how to check whether a number is a Magic Number or not. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |