Why is this if statement not working? New in python 3

I cannot understand for me why this if statement does not work in Python 3. I have always worked with python 2.7, but I need to get to know 3. Here is my code

print("Answer the question! [(Y)es or (N)o]: ") answer = input() print(answer) if answer == "y": print("OK") print("done") 

I am starting this code, getting the question presented, normal, which is normal. For input, I give it one lowercase case y. I see that "y" is printed back to me, but then the program bypasses the if statement and goes straight to the point. What simple thing am I doing wrong?

+6
source share
2 answers

Good for starters, your code works! I tested it online and it works. Maybe something with your IDE or with any Python you use. I had such errors when using Jython.

But it works here!

+1
source

I see no problems http://ideone.com/Vk9Hdo , Try the following:

 print("Answer the question! [(Y)es or (N)o]: ") answer = input() print(answer) if answer == "y": print("OK") print("done") 

Exit

 Answer the question! [(Y)es or (N)o]: y OK done 
+1
source

All Articles