← Back to challenges

Count Palindrome Numbers in a Range

PythonHardstringscontrol_flownumbers

Instructions

Create a function that returns the number of palindrome numbers in a specified range (inclusive).

For example, between 8 and 34, there are 5 palindromes: 8, 9, 11, 22 and 33. Between 1550 and 1552 there is exactly one palindrome: 1551.

Examples

count_palindromes(1, 10) ➞ 9

count_palindromes(555, 556) ➞ 1

count_palindromes(878, 898) ➞ 3

Notes

  • A palindrome number is a number which remains the same when its digits are reversed. For example, 2552 reversed is still 2552. The reflectional symmetry of this number makes it a palindromic number.
  • Single-digit numbers are trivially palindrome numbers.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Determine If Two Numbers Add up to a Target Value