I can't figure out for the life of me why this if statement isn't working in Python 3. I have always worked with python 2.7 but I need to get familiar with 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 start this code, get presented with the question, ok, that's normal. For input I give it a single lowercase y. I see that 'y' printed back to me, but then the program bypasses the if statement and goes straight to done. What simple thing am I doing wrong?
Well for starters, your code works! I've tested it online and it works. Probably something with your IDE or with whatever Python you are using. I've had errors like this when using Jython.
I dont see any problem http://ideone.com/Vk9Hdo, Try this:
print("Answer the question! [(Y)es or (N)o]: ")
answer = input()
print(answer)
if answer == "y":
print("OK")
print("done")
Output
Answer the question! [(Y)es or (N)o]:
y
OK
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With