Find the first and last digits of a number.

In this program, we will find the first and last digits of a number.

Steps to solve the program
  1. Take a number as input and convert it into a string using str().
  2. Use for loop to iterate over indexes of the number.
  3. Using logic print the first and last digits of a number.
				
					num = 2665
str1 = str(num)

for i in range(len(str1)):
    if i == 0:
        print("First number in the gievn number : ",str1[i])
    elif i == len(str1)-1:
        print("Last number in the gievn number : ",str1[i])
				
			

Output :

				
					First number in the gievn number :  2
Last number in the gievn number :  5
				
			

count the number of digits in a number

find the sum of the first and last digits of a number

Leave a Comment