A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 3 years ago
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?
anonymous
 3 years ago
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?

This Question is Closed

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0what is this for? c++, c, java?

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0It'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.

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0This 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

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0Something like this should work def isPalindrome(m,n): for i in range(m,n): if str(i)==str(i)[::1]: print i

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0This 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

rsmith6559
 3 years ago
Best ResponseYou've already chosen the best response.0Does it work with 4 digit numbers?

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0Seems 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
Ask your own question
Sign UpFind more explanations on OpenStudy
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.