{"id":18577,"date":"2021-08-26T10:38:21","date_gmt":"2021-08-26T05:08:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=18577"},"modified":"2021-11-22T18:37:18","modified_gmt":"2021-11-22T13:07:18","slug":"python-program-to-check-trimorphic-number-or-not","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-trimorphic-number-or-not\/","title":{"rendered":"Python Program to Check Trimorphic Number or Not"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check Abundant Number or Not<\/a> Cube the number you’ve been given. If the given number appears in the cube number in the last means, it is referred to as a trimorphic number.<\/p>\n For example:<\/p>\n Let the given number =25<\/p>\n The cube of the number = 25*25*25= 15625<\/strong><\/p>\n The Given number 25 is present at the end.<\/p>\n Therefore, 25 is a Trimorphic Number.<\/strong><\/p>\n The examples of the first few Trimorphic Numbers<\/strong> are 1, 4, 5, 6, 9, 24, 25, 49, 51, 75, 76, 99, 125, 249, 251, 375, 376, 499, and so on.<\/p>\n Given the number and the task is to check\u00a0whether the given number is a Trimorphic Number or not.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to check whether the given number is a Trimorphic Number or not:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Check Abundant Number or Not Trimorphic Number: Cube the number you’ve been given. If the given number appears in the cube number in the last means, it is referred to as a trimorphic number. For example: Let the given number =25 The cube of the …<\/p>\n
\nTrimorphic Number:<\/strong><\/p>\nGiven Number = 75<\/pre>\n
The given number { 75 } is a Trimorphic number<\/pre>\n
Given Number = 30<\/pre>\n
The given number { 30 } is Not a Trimorphic number<\/pre>\n
Program to Check Trimorphic Number or Not in Python<\/h2>\n
\n
Method #1: Using Slicing (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_numb = 75\r\n# Calculate the cube root of the given number and convert it into the string using the str() function.\r\n# Store it in another variable.\r\ncube_numb = str(gvn_numb**3)\r\n# Convert the given number to a string using the str() function and store it in\r\n# another variable.\r\nstr_numb = str(gvn_numb)\r\n# Calculate the length of the above-obtained string number using the len() function\r\n# and store it in another variable.\r\nlen_str = len(str_numb)\r\n# Check if the\u00a0cube_root[-len_string:](negative\u00a0slicing) is equal to the string number using the\r\n# if conditional statement and slicing.\r\nif(cube_numb[-len_str:] == str_numb):\r\n # If the statement is true, then print \"The given number is a Trimorphic Number\".\r\n print(\"The given number {\", gvn_numb, \"} is a Trimorphic number\")\r\nelse:\r\n # If it is false, then print \"The given number is Not a Trimorphic Number\".\r\n print(\"The given number {\", gvn_numb, \"} is Not a Trimorphic number\")\r\n<\/pre>\n
The given number { 75 } is a Trimorphic number<\/pre>\n
Method #2: Using Slicing (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function and\r\n# store it in a variable.\r\ngvn_numb = int(input(\"Enter some random number = \"))\r\n# Calculate the cube root of the given number and convert it into the string using the str() function.\r\n# Store it in another variable.\r\ncube_numb = str(gvn_numb**3)\r\n# Convert the given number to a string using the str() function and store it in\r\n# another variable.\r\nstr_numb = str(gvn_numb)\r\n# Calculate the length of the above-obtained string number using the len() function\r\n# and store it in another variable.\r\nlen_str = len(str_numb)\r\n# Check if the\u00a0cube_root[-len_string:](negative\u00a0slicing) to the string number using the\r\n# if conditional statement and slicing.\r\nif(cube_numb[-len_str:] == str_numb):\r\n # If the statement is true, then print \"The given number is a Trimorphic Number\".\r\n print(\"The given number {\", gvn_numb, \"} is a Trimorphic number\")\r\nelse:\r\n # If it is false, then print \"The given number is Not a Trimorphic Number\".\r\n print(\"The given number {\", gvn_numb, \"} is Not a Trimorphic number\")\r\n<\/pre>\n
Enter some random number = 30\r\nThe given number { 30 } is Not a Trimorphic number<\/pre>\n
\n