Python Forum
Variable not defined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Variable not defined (/thread-1688.html)



Variable not defined - ASDF - Jan-20-2017

This is very simple (as I am new to coding) but why does this keep saying 'yes' is not defined?
def shop(answer):

    if answer == yes
        return 10
    else:
        return 30
collingwood_shop = yes
grey_shop = yes
print collingwood_shop, grey_shop
Thanks!


RE: HELP PLEASE! - j.crater - Jan-20-2017

Hello,
It would fit this forum better if you used code tags for the part of your post that contains code. And to change your thread title into something more meaningful. You can edit your post.

if answer == yes
compares variable answer and variable yes. Your variable yes does not appear before, so Python doesn't recognize it.
However, I believe your intention was to use yes as a string. In that case you should put it in quotes ('yes' or "yes").


RE: HELP PLEASE! - micseydel - Jan-20-2017

On top of the previous comment, I wish to point out that (1) you have a syntax error, a missing colon for your if, and (2) you never call the function you define.

Is this homework? What is your goal? Where are you learning Python from? The code you've posted suggests you might be developing a bad habit of writing too much code before testing what you've written so far.