{"id":8771,"date":"2023-11-04T11:11:28","date_gmt":"2023-11-04T05:41:28","guid":{"rendered":"https:\/\/python-programs.com\/?p=8771"},"modified":"2023-11-10T12:16:42","modified_gmt":"2023-11-10T06:46:42","slug":"python-program-to-form-an-integer-that-has-the-number-of-digits-at-tens-place-and-the-least-significant-digit-of-the-entered-integer-at-ones-place","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-form-an-integer-that-has-the-number-of-digits-at-tens-place-and-the-least-significant-digit-of-the-entered-integer-at-ones-place\/","title":{"rendered":"Python Program to Form an Integer that has the Number of Digits at Ten\u2019s Place and the Least Significant Digit of the Entered Integer at One\u2019s Place"},"content":{"rendered":"
Given a number which is integer , the task is to create an integer with the number of digits at ten’s place and the least significant digit of the entered integer at one’s place.<\/p>\n
Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n given number = 37913749<\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n There are several ways to create an integer with the number of digits at ten’s place and the least significant digit of the entered integer at one’s place some of them are:<\/p>\n Drive into Python Programming Examples<\/a> and explore more instances related to python concepts so that you can become proficient in generating programs in Python Programming Language.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/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 Related Programs<\/strong>:<\/p>\n Given a number which is integer , the task is to create an integer with the number of digits at ten’s place and the least significant digit of the entered integer at one’s place. Examples: Example1: Input: given number = 37913749 Output: The required number = 89 Example2: Input: given number =78329942 Output: The required …<\/p>\nThe required number = 89<\/pre>\n
given number =78329942<\/pre>\n
The required number = 82<\/pre>\n
Create an integer with the number of digits at ten’s place and the least significant digit of the entered integer at one’s place in Python<\/h2>\n
\n
Method #1:Using while loop and String Conversion ( Static Input)<\/h3>\n
\n
# given number numb\r\nnumb = 37913749\r\n# Taking a temporary variable which stores the given number\r\ntempNum = numb\r\n# Take a variable which stores the count of digits and initialize it with 0\r\ncountTotalDigits = 0\r\n# looping till the given number is greater than 0\r\nwhile(numb > 0):\r\n # increasing the count of digits by 1\r\n countTotalDigits = countTotalDigits+1\r\n # Dividing the number by 10\r\n numb = numb\/\/10\r\n# converting the temporary variable to string\r\nstrnum = str(tempNum)\r\n# Extracting least significant digit\r\nleastSigDigit = strnum[-1]\r\n# converting the count Total Digits to string\r\ncountTotalDigits = str(countTotalDigits)\r\n# calculating required number\r\nresnum = countTotalDigits+leastSigDigit\r\nprint(\"The required number =\", resnum)\r\n<\/pre>\n
The required number = 89<\/pre>\n
\n
Method #2:Using while loop and String Conversion ( User Input)<\/h3>\n
\n
# given number numb\r\nnumb = int(input(\"enter any number = \"))\r\n# Taking a temporary variable which stores the given number\r\ntempNum = numb\r\n# Take a variable which stores the count of digits and initialize it with 0\r\ncountTotalDigits = 0\r\n# looping till the given number is greater than 0\r\nwhile(numb > 0):\r\n # increasing the count of digits by 1\r\n countTotalDigits = countTotalDigits+1\r\n # Dividing the number by 10\r\n numb = numb\/\/10\r\n# converting the temporary variable to string\r\nstrnum = str(tempNum)\r\n# Extracting least significant digit\r\nleastSigDigit = strnum[-1]\r\n# converting the count Total Digits to string\r\ncountTotalDigits = str(countTotalDigits)\r\n# calculating required number\r\nresnum = countTotalDigits+leastSigDigit\r\nprint(\"The required number =\", resnum)\r\n<\/pre>\n
enter any number = 78329942\r\nThe required number = 82<\/pre>\n
Method #3: Using len() and indexing by converting number to string (Static Input)<\/h3>\n
\n
# given number numb\r\nnumb = 82179\r\n# Using the str() method, convert the given number to a string.\r\nstrnum = str(numb)\r\n\r\n# Determine the number of digits in the given number by computing\r\n# the length of the string with the len() function.\r\ncountTotalDigits = len(strnum)\r\n\r\n# Extracting least significant digit\r\nleastSigDigit = strnum[-1]\r\n# converting the count Total Digits to string\r\ncountTotalDigits = str(countTotalDigits)\r\n# calculating required number\r\nresnum = countTotalDigits+leastSigDigit\r\nprint(\"The required number =\", resnum)\r\n<\/pre>\n
The required number = 59<\/pre>\n
\n