Keep receiving syntax errors in series of conditionals, beginner Python #21471
-
I’m attempting to solve a palindromic puzzle with Python that requires me to have the following conditionals
I want to solve this problem using only a Right now I have:
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 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
retrohp:
A conditional must contain a condition (a value that is You always need to assign a variable before you can use it. A variable that hasn’t been assigned doesn’t exist, that’s why you get an error saying it’s undefined. I’m not sure why you’re trying to do an assignment in the
I’m seeing a few more issues here:
retrohp:
Finally, if you use a |
Beta Was this translation helpful? Give feedback.
A conditional must contain a condition (a value that is
True
orFalse
, or can be converted to one of those). An assignment is no condition, so you get a syntax error.You always need to assign a variable before you can use it. A variable that hasn’t been assigned doesn’t exist, that’s why you get an error saying it’s undefined.
I’m not sure why you’re trying to do an assignment in the
if
condition here, it looks the thing you put in the body of the conditional is what you actually want to be the condition. If you want to assignx_str
and then compare its slices, do this: