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

Beginner Python – Little help on simple code

I am super new to Python and programming and am trying to digest some basics I’ve learned.

I am stuck on a running a question in python and returning differing statements depending on the reply – yes/no.

Here’s my code;

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

answer = input('Would you go on strike')
if answer == 'yes':
    print ('You are\'t a strikebreaker')
else:
    print ('You are a strikebreaker')

Whatever I answer, python prints the ‘else’ response. I have checked a few examples and tutorials and that appears to be the simple code.

Please help?

I followed a few tutorials and expected to get different print statements correlating to the input response.

>Solution :

Strange, what you’re doing should work, I just tried it out myself.

Be aware that string comparisson is case sensetive.

What version of python are you running? Make sure you are using python 3.x.

If you use python 2.x you will have to use raw_input() instead of input()

Hope this helps

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