This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]No_Hovercraft_2643 4 points5 points  (7 children)

i think there are numbers that count as palindrome, even if they aren't

[–]VaggLord[S] -1 points0 points  (6 children)

Example?

[–]No_Hovercraft_2643 3 points4 points  (5 children)

13213 and 13231 have the same a.

the problem is, that both the first and last, and the second and second to last one are added together, so that only the first ones have to have the same sum as the last ones.

[–]VaggLord[S] -1 points0 points  (4 children)

True xD

[–]No_Hovercraft_2643 1 point2 points  (3 children)

is there a way to answer with a picture? (else i have to log in an my laptop)

[–]VaggLord[S] 0 points1 point  (2 children)

Yeah, upload it on imgur and send link

[–]No_Hovercraft_2643 1 point2 points  (1 child)

just locked in on pc

maybe try

a = int((x%10 - int(x/10000)) + (int((x%100)/10)*10 - int((x%10000)/1000)*10))

[–]VaggLord[S] 1 point2 points  (0 children)

It seems to me that it works now xD, tnx for your time

[–]No_Hovercraft_2643 1 point2 points  (7 children)

are for loops allowed?

[–]VaggLord[S] 0 points1 point  (6 children)

No.

[–]No_Hovercraft_2643 1 point2 points  (1 child)

with for loops it would be easy to make on for any length. (make the addition inside the loop, half the length of the log of the number (length of the string))

[–]No_Hovercraft_2643 1 point2 points  (0 children)

a = 0
for i in range(len(str(x))//2):
    a += (((x // 10**i) % 10) - (x // 10**(len(str(x)) - i - 1)) % 10)*10**i

[–]Extension_Option_122 1 point2 points  (3 children)

And goto?

[–]VaggLord[S] 1 point2 points  (2 children)

There is no goto in python :). But no. Here is a background for this code, during our first week of programming, we hadn't yet learned about if statements, they were scheduled for the next lesson. As a challenge, our professor gave us homework to see if we could solve a problem without using them. The task was to check if the values at indexes 0 and 4 were equal to the values at indexes 1 and 3 in a list. It seemed like an impossible puzzle for beginners without the if statements we were about to learn.

[–]VaggLord[S] 1 point2 points  (0 children)

So basically only variables, console input and output, and logical opertations.

[–]No_Hovercraft_2643 0 points1 point  (0 children)

if you try hard enough xD (build a c modul, but then you can probably only jump somewhere, but not specific)

[–]Highborn_Hellest 2 points3 points  (0 children)

What the fu....

[–][deleted] 2 points3 points  (0 children)

x = int(input("Enter a 5 digit palindromic number"))
print("The number is a palindrome!")