Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am having trouble with indentations and syntax with my Python code

it is not working as intended
What it is supposed to do is to ask if a person likes ATTACK ON TITAN if yes then it will ask for a character name from the anime and i have different code lines for eren, mikasa and levi respectively for the one chosen by the user
But only the first if after assigning of value to chara variable but when i change the code on line 6 to

if chara == "Eren" or chara == "eren"

then it works till mikasa’s part but still doesn’t work for levi

I will be happy to answer any questions u may have regarding the post Thankyou for taking ur important time to read this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

First pic of the code

Second pic of the code

Third and last pic of the code

P.S
I AM REALLY SORRY IF MY QUESTION IS NOT CLEAR TRUST ME I TRIED MY BEST SINCE THIS IS MY FIRST ACTUAL QUESTION IN THIS PLATFORM. LIKE REALLY I AM FIGURING OUT WHAT THE BUTTONS ON TOP OF THIS TEXT EDITOR DO AS I AM RIGHTING THIS SO MODS PLZ DONT DELETE OR CLOSE THE QUESTION I CHECKED ALOT OF POSTS BUT CAN’T FIND AN ANSWER

>Solution :

The problem are the lines

elif chara == "Miakas" or "Mikasa":
# ...
elif chara == "Levi" or "levi":

This doesn’t do what you expect it to do. If chara == "Miakas" is False, the second part of that expression is evaluated for true-ishness. The second part is Mikasa, which is something, so it’s true-ish. In other words, the expression chara == "Miakas" or "Mikasa" can never be False, so the indented block in the elif is always executed.

Rewrite it to read

elif chara == "Miakas" or chara == "Mikasa":

or

elif chara in ["Miakas", "Mikasa"]:

to avoid this pitfall.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading