How come my if statement isn't working properly?

Question:

Python code

IDLE Shell Python

I’m a very beginner coder, so bear with me, but my if statement is printing out even when the required name isn’t typed in. For example, if I typed in Apple, it would still print out Charmander and Charmeleon.

I tried assigning my if statement to input, name, but nothing seems to work, and I’m at a loss for ideas. 

Asked By: PlasmaTL

||

Answers:

Try using name.lower() so your input will be in lower case and then compare it only with "charmender"

if name.lower()=="charmender":
    print('A')
elif name.lower()=="charmeleon":
    print('B')
Answered By: P-A

In your Python code, try to use elif statement, after the first if statement, because two if statements are used now one after another.Make sure you follow the rules for posting your answer correctly.

Answered By: David

First of all you are not using or operator in a correct way.
change it to

if name == "xyz" or name == "abc":

When your are using if name == or this condition will be always true.

Answered By: Kevin Bhavsar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.