In this program, we will find the first and last digits of a number.
Steps to solve the program
- Take a number as input and convert it into a string using str().
- Use for loop to iterate over indexes of the number.
- 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