This is a Python Program to form an integer that has the number of digits at the ten’s place and the least significant digit in the one’s place.
The program takes an integer and forms a new integer which has the number of digits at the ten’s place and the least significant digit in the one’s place.
1. Take in an integer and store it in a variable.
2. Make a separate copy of the integer.
3. Using a while loop, calculate the number of digits in the integer.
4. Convert the copy of the integer and the count of the number of digits to string.
5. Concatenate the last digit of the integer to the count and convert the new integer back to int.
6. Print the newly formed integer.
Here is source code of the Python Program tto form an integer that has the number of digits at the ten’s place and the most significant digit in the one’s place. The program output is also shown below.
n=int(input("Enter the number:")) tmp=n k=0 while(n>0): k=k+1 n=n//10 b=str(tmp) c=str(k) d=c+b[k-1] print("The new number formed:",int(d))
1. User must enter the number and store it in a variable.
2. A copy of the variable is made because the original value of the variable would be changed for counting the number of digits.
3. The while loop is used and the last digit of the number is obtained by using the modulus operator.
4. Each time a digit is obtained, the count value is incremented.
5. The number of digits of the variable and the number is converted to string for ease of concatenation.
6. Then the last digit of the string is obtained and concatenated to the count variable.
7. The new number formed is then printed.
Case 1: Enter the number:129 The new number formed: 39 Case 2: Enter the number:24678 The new number formed: 58
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.