def largest(min_factor, max_factor):
if max_factor < min_factor:
raise ValueError("min must be <= max")
factors = []
result = -1
for i in range(min_factor, max_factor + 1):
for j in range(i, max_factor + 1):
if i*j > result:
if isPalindrome(i*j):
result = i*j
factors.clear()
factors.append(i)
factors.append(j)
if result == -1:
return None
return result, factors
def smallest(min_factor, max_factor):
if max_factor < min_factor:
raise ValueError("min must be <= max")
factors = []
result = sys.maxsize
for i in range(min_factor, max_factor + 1):
for j in range(i, max_factor + 1):
if i*j < result:
if isPalindrome(i*j):
result = i*j
factors.clear()
factors.append(i)
factors.append(j)
if result == sys.maxsize:
return None
return result, factors
def isPalindrome(number):
string = str(number)
if string == string[::-1]:
return True
return False
#Python Palindrome Products
25 messages · Page 1 of 1 (latest)
The only tests that pass are the ones where the TypeError gets thrown
P.S. This same error is thrown for all the other test cases
UPDATE : I changed a bit how I return the values and now I also pass the tests where no palindrome exists
What does the picture show/say? I can see it (that it is there) but not what it shows. Is it text that could benefit from everyone that is interested in being able to read it?
It seems too large to only say what you posted it says.
Did that solve your problem or are just fewer tests failing?
fewer tests failing
I posted a screenshot of one of the failed test cases, but the only important information (other than what the test entails), is the error message
Since you modified your solution, can you post this new version?
Then what the test entails would likely be good information to show as text as well, right?
def largest(min_factor, max_factor):
if max_factor < min_factor:
raise ValueError("min must be <= max")
factors = []
result = -1
for i in range(min_factor, max_factor + 1):
for j in range(i, max_factor + 1):
if i*j > result:
if isPalindrome(i*j):
result = i*j
factors = [i, j]
if result == -1:
return None, []
return result, factors
def smallest(min_factor, max_factor):
if max_factor < min_factor:
raise ValueError("min must be <= max")
factors = []
result = sys.maxsize
for i in range(min_factor, max_factor + 1):
for j in range(i, max_factor + 1):
if i*j < result:
if isPalindrome(i*j):
result = i*j
factors = [i, j]
if result == sys.maxsize:
return None, []
return result, factors
def isPalindrome(number):
string = str(number)
if string == string[::-1]:
return True
return False
this is the new solution, minimal changes to what is returned
Any error messages?
Code Run
value, factors = smallest(min_factor=1, max_factor=9)
self.assertEqual(value, 1)
self.assertFactorsEqual(factors, [[1, 1]])
Test Failure
TypeError: 'int' object is not iterable
my guess is my issue is in the format of what I'm returning, since it runs just fine on my machine
value, factors = smallest(min_factor=1, max_factor=9)
self.assertEqual(value, 1)
self.assertFactorsEqual(factors, [[1, 1]])```
and here is an example of a test case, to see what is expected from me. I feel like what I am returning and what they want me to return is the same
This is one of the tests:
def test_find_the_largest_palindrome_from_single_digit_factors(self):
value, factors = largest(min_factor=1, max_factor=9)
self.assertEqual(value, 9)
self.assertFactorsEqual(factors, [[1, 9], [3, 3]])
The largest possible palindrome product from two factors in the range [1, 9] is 9.
There are two ways to get that product: 1 * 9 and 3 * 3.
Therefore you have to include them both in the factors
YEA!!
I just noticed that too
lemme see if it improves it
it passed all tests!🥳
thanks for the support 🙂
Thank you for the support. Providing information that we can read (and copy and paste as text) is definitely helpful!