Variable not defined PYTHON 3.5.2
<pre><code>def GameMode():#creates a function with name of gamemode
    global wrong_answer_1
    for keys,values in keywords.items():#checks for the right answer
        if keys == code:#if the keys equal to the code value
            keyword_c = values
            global keyword_c
    for keys,values in definition.items():#checks for the right answer
        if keys == code + 1:#if the keys equal the code add 1
            definition_c = values#set s to be the values
    for keys,values in definition.items():#checks for the right answer
        if inc == keys:#if the keys equal the code add 1
            wrong_answer_1 = values#set s to be the values
    for keys,value in definition.items():#For the keys in the dictionary
        if keys == inc2:#if the keys equal to a value
            global wrong_answer_2
            wrong_answer_2 = value

    print(wrong_answer_2, "Hi")
</code></pre>

<p>I am trying to get my variables keyword_c, definition_c, wrong_answer_1 and wrong_answer_2 to be global so I can use them in another function but I can't seem to get it to work, I am a bit of a newb when it comes to python.
I've tried using "global" as you can see above and I have tried to call variables and pass them but I don't fully understand it enough to be able to figure it out.</p>

<pre><code>keyword_c = ''
definition_c = ''
wrong_answer_1 = ''
wrong_answer_2 = ''
</code></pre>

<p>I have already predefined the variables as well to see if that did anything, they are there but its now just an empty string so my program is picking up the fact that the variable is being defined.</p>

<pre><code>Traceback (most recent call last):
  File "D:\Program.py", line 67, in &lt;module&gt;
   GameMode()#calls the function
  File "D:\Program.py", line 55, in GameMode
    print(wrong_answer_2, "Hi")
NameError: name 'wrong_answer_2' is not defined
</code></pre>

<p>here is the error I get if I remove the original line that sets it as a blank string</p>

<p>I am not sure what your function is supposed to be doing; it is hard to guess with all the syntax errors, but the following fixes the syntax errors, using a single global at the top of the function for everything which is not defined within the function.</p>

<pre><code>def GameMode():#creates a function with name of gamemode
    global inc, inc2, code, wrong_answer_1, wrong_answer_2, keyword_c
    for keys,values in keywords.items():#checks for the right answer
        if keys == code:#if the keys equal to the code value
            keyword_c = values
    for keys,values in definition.items():#checks for the right answer
        if keys == code + 1:#if the keys equal the code add 1
            definition_c = values#set s to be the values
    for keys,values in definition.items():#checks for the right answer
        if inc == keys:#if the keys equal the code add 1
            wrong_answer_1 = values#set s to be the values
    for keys,value in definition.items():#For the keys in the dictionary
        if keys == inc2:#if the keys equal to a value
            wrong_answer_2 = value

    print(wrong_answer_2, "Hi")

keywords = {
    1: 'a',
}
definition = {
    1: 'a',
}
code = 1
inc = 1
inc2 = 1
wrong_answer_1 = None
wrong_answer_2 = None
keyword_c = None

GameMode()
print(inc, inc2, code, wrong_answer_1, wrong_answer_2, keyword_c)
</code></pre>

<p>That will output:</p>

<pre><code>a Hi
1 1 1 a a a
</code></pre>

python variables global-scope python-3.5.2