Answer to Question #321199 in Python for FIRST AND LAST DIG

Question #321199

First and last digits

Given two numbers 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 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 number are M is 5and 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
2022-04-13T16:05:25-0400
m = int(input("Enter the START value of the range (M): "))
n = int(input("Enter the END value of the range (N): "))
count = 0
for i in range(m, n + 1):
    if i < 10:
        count += 1
        continue
    else:
        if i // 10 == i % 10 or i // 100 == i % 100 or i // 1000 == i % 1000:
            count += 1
print("Counts of the numbers which have the same first and last digits" + str(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