Python Forum
can you help me out with the code for reversible numbers under 100?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can you help me out with the code for reversible numbers under 100?
#1
class ReversibleNumbers:
    def __init__(self, size = 100):
        self.size = size
    def get_total_reversible_numbers(self):
        s = set()
        for i in range(11, self.size):
            reverse = int(str(i)[::-1])
            if i != reverse:
                result = i + reverse
                if result % 2 != 0:
                    s.add(i)
        return s
r = ReversibleNumbers()
print(r.get_total_reversible_numbers())                  
i am not able to obtain the correct output
Reply
#2
What output do you get? What is the correct output? You've just given us code without any explanation; please don't make us guess. In addition, where do you think the problem lies? What have you done to debug it?
Reply
#3
the output is supposed to be
{12,21,14,41,16,61,18,81,23,32,25,52,27,72,34,43,36,63,45,54}
but the output which i am getting is
{12, 14, 16, 18, 21, 23, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 45, 47, 49, 50, 52, 54, 56, 58, 61, 63, 65, 67, 69, 70, 72, 74, 76, 78, 81, 83, 85, 87, 89, 90, 92, 94, 96, 98}
reversible numbers description is:
Some positive integers n have the property that the sum [n + reverse(n)] consists entirely of odd (decimal) digits.

For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409 and 904 are reversible.

Reversible number should meet the following conditions:
1. Leading zeroes are not allowed in either n or reverse(n).
2. No duplicate digit should be in n
Reply
#4
You missed the most important part of my questions: what have you done to debug the problem?
Reply
#5
yeah there should be not multiples of 10
Reply
#6
That doesn't answer the question. What I mean is, how have you tried to find out what's wrong with the code?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,755 May-09-2019, 12:19 PM
Last Post: Pleiades
  Writing a code with 3 digit numbers while they cant contain 0 and then sum them AFKManager 2 2,401 Jan-13-2019, 12:00 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020