I’m attempting to solve a palindromic puzzle with Python that requires me to have the following conditionals
- The number is 6 digits long
- The last 4 digits are palindromic
- One mile later last 5 digits are palindromic
- One mile later middle 4 digits are palindromic
- One mile later all 6 digits are palindromic If all these conditionals are fulfilled the puzzle is solved The full problem is found here if you need more context
I want to solve this problem using only a
while loop, slicing, and
if statements, I haven’t learned about
def statements yet.
Right now I have:
winner = False while x < 1000000 and winner: if x_str = str(x) : x_str[2:6] == x[5:1:-1] if x1_str = str(x+1) : x1_str[1:6] == x1[-1:0:-1] if x2_str = str(x+2) : x2_str[1:5] == x2[-2:-6:-1] if x3_str = str(x+3) : x3_str[0:6] == x3[-1:-7:-1] if winner(True): print ("Great! The answer is", x)
But I get a syntax error on my first conditional. If I change the assignment operator to == instead, then I get undefined error for all my variables. I’m not sure what to do here? I’ve only been coding for two weeks so it might be a very simple error.
Thanks so much