How come my if statement isn't working properly?
Question:
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.
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')
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.
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.
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.
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')
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.
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.