issues importing a script
<p>Hello i have been working on this simple script and i have run into some rather annoying problems that i can not fix myself with the def. and import function it just won't work. here is the main script </p>

<pre><code>import time         # This part import the time module
import script2      # This part imports the second script

def main():
    print("This program is a calaulater have fun using it")
    name = input("What is your name? ")
    print("Hello",name)
    q1 = input("Would you like to some maths today? ")

if q1 == "yes":
    script2 test()

if q1 == "no":
    print("That is fine",name,"Hope to see you soon bye")
    time.sleep(2)



if __name__ == '__main__':
    try:
        main()
    except Exception as e:
        time.sleep(10)      
</code></pre>

<p>And then the second script is called script2 here is that script as well
    import time</p>

<pre><code>def test():
    print("You would like to do some maths i hear.")
    print("you have some truely wonderfull option please chooice form the list below.")
</code></pre>

<p>That is my script currently but it deos not work please help me.</p>

<p>This is an error:</p>

<pre><code>def main():
    #...
    q1 = input("Would you like to some maths today? ")

if q1 == "yes":
    # ...
</code></pre>

<p>Firstly, the <code>q1</code> in <code>main()</code> and the <code>q1</code> outside are not the same variable.</p>

<p>Secondly, <code>if q1 == "yes":</code> is executed before <code>q1 = input(...)</code>, because <code>main()</code> was not called yet.</p>

<p>The solution would be to return the <code>q1</code> value from main and only then use it:</p>

<pre><code>def main():
    # ...
    return q1

if __name__ == '__main__':
    # ...
    result_from_main = main()    
    if result_from_main == "yes":
       # ...
</code></pre>

<p>Of course, the all names are completely messed up now, but that is a different problem...</p>

python function python-import