Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Gen.Gluck
Group Title
I have to create a function that prints the palindromes between two numbers, this is what I have so far:
def isPalindrome(n,m):
for i in range(n,m):
i=0
dig=i%10
rev=rev*10+dig
i=i/10
print(i)
can anyone assist?
 one year ago
 one year ago
Gen.Gluck Group Title
I have to create a function that prints the palindromes between two numbers, this is what I have so far: def isPalindrome(n,m): for i in range(n,m): i=0 dig=i%10 rev=rev*10+dig i=i/10 print(i) can anyone assist?
 one year ago
 one year ago

This Question is Closed

timo86m Group TitleBest ResponseYou've already chosen the best response.0
what is this for? c++, c, java?
 one year ago

msmithhnova Group TitleBest ResponseYou've already chosen the best response.0
It's Python and the above code does this. It just sets i to 0, gets the modulus of 0/10 so dig is 0, then takes rev and multiplies it by ten and adds 0 to it which will create an error if rev wasn't defined elsewhere. let's pretend it was set to 0 elsewhere, so 0*10+0 is 0. Then you divide i by 10, since i was never changed it's still 0 so we make it 0 again. It repeats this process a number of times equal to the difference of m and n. And then we print 0 (well, actually we don't because based on the indentation it is outside the function and therefore doesn't know what i is so just gives us an error). Not sure what you thought you were doing here nor do I understand what you mean by "prints the palindromes between two numbers". Normally something like 'isPalindrome' would simply return true if the item is a palindrome and false if it is not. But then the function only needs 1 argument and not two. With two arguments maybe you are trying to see if one is the reverse of the other, hard to say. You will need to explain what you mean a little better and provide sample input/output.
 one year ago

Gen.Gluck Group TitleBest ResponseYou've already chosen the best response.0
This is what the program is supposed to look like: Enter the starting point N: 200 Enter the ending point M: 800 The palindrome numbers are: 313 353 373 383 727 757 787 797
 one year ago

msmithhnova Group TitleBest ResponseYou've already chosen the best response.0
Something like this should work def isPalindrome(m,n): for i in range(m,n): if str(i)==str(i)[::1]: print i
 one year ago

Gen.Gluck Group TitleBest ResponseYou've already chosen the best response.0
This worked: def isPalindrome(n,m): for i in range(n,m): if str(i)==str(i)[::1]: print(i) n= eval(input("Enter the starting point N:\n")) m=eval(input("Enter the ending point M:\n")) print(isPalindrome(n,m)) Thank you
 one year ago

rsmith6559 Group TitleBest ResponseYou've already chosen the best response.0
Does it work with 4 digit numbers?
 one year ago

msmithhnova Group TitleBest ResponseYou've already chosen the best response.0
Seems to >>> isPalindrome(1000,10000) 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 2002 2112 2222 2332 2442 2552 2662 2772 2882 2992 3003 3113 3223 3333 3443 3553 3663 3773 3883 3993 4004 4114 4224 4334 4444 4554 4664 4774 4884 4994 5005 5115 5225 5335 5445 5555 5665 5775 5885 5995 6006 6116 6226 6336 6446 6556 6666 6776 6886 6996 7007 7117 7227 7337 7447 7557 7667 7777 7887 7997 8008 8118 8228 8338 8448 8558 8668 8778 8888 8998 9009 9119 9229 9339 9449 9559 9669 9779 9889 9999
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.