Answer to Question #173933 in Python for phani

Question #173933
First and Last Digits
Given two integers M and N, write a program to count of the numbers which have the same first and last digits in the given range M to N (inclusive of M and N).
Input

The first line of input will contain a positive integer M.
The second line of input will contain a positive integer N.
Output

The output should be an integer denoting the count of the numbers in the range which meet the given condition.
Explanation

For example, if the given numbers are M is 5 and N is 30, the numbers which have the first and last digit equal in the given range (5, 6, ..., 29, 30) are 5, 6, 7, 8, 9, 11 and 22. So the output should be 7.
Sample Input 1
5
30
Sample Output 1
7

Sample Input 2
1
10
Sample Output 2
9
1
Expert's answer
2021-03-21T19:36:00-0400
n = int(input('Enter number N: '))
m = int(input('Enter number M: '))
count = len([1 for item in range(n,m+1) if str(item)[0] == str(item)[-1]])
print ('The quanity of numbers with the same first and last digit:', count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS