title: Printing variable from one module to another?
body: <p>As part of my coursework for computing I need to create a program that gives solutions to problems on a device. For task 3 I would like to use a modified version of my task 2 as part of it as a module instead of coding a it again, I keep on coming up with errors can any one help with this code?</p>
  
  <p><strong>Task 3 code:</strong></p>
  
  <pre><code>from random import randint
  from task2 import trouble2
  caseNo = randint(999,10000)
  
  def main():
  
      devType = input("What type of device is it? ")
      devType = devType.lower()#converts the input devType to be lowercase
  
      text_file = open(str(caseNo)+".txt", "a")#opens/creates the file with the name that caseNo is and appends to it
      text_file.write(devType+"\n")#appends devtype to the file
      text_file.close()#closes the file
  
      devMake = input("What is the make of the device? ")
      devMake = devMake.lower()
  
      text_file = open(str(caseNo)+".txt", "a")
      text_file.write(devMake+"\n")
      text_file.close()
  
      devModel = input("What is the model of the device? ")
  
      text_file = open(str(caseNo)+".txt", "a")
      text_file.write(devModel+"\n")
      text_file.close()
  
      devMemory = input("How much memory does the phone have in GB? ")
  
      text_file = open(str(caseNo)+".txt", "a")
      text_file.write(devMemory+"\n")
      text_file.close()
  
  main()
  task2.trouble2()
  global start
  print(start)
  </code></pre>
  
  <p><strong>Task 2 code</strong></p>
  
  <pre><code>from time import * #imports the time module
  import os #imports the os module
  import datetime #imports the date and time module
  
  
  def trouble2():
      global start
      smashed = ['shattered', 'smashed', 'cracked'] #creates a list called smashed
      wifi = ['internet', 'conection', 'wifi'] #creates a list called wifi
      button = ['home', 'lock', 'button'] #creates a list called button
      temp = ['high', 'hot', 'cold', 'boiling', 'freezing', 'low', 'temp', 'temperature'] #creates a list called temp
      virus = ['virus', 'slow', 'bug'] #creates a list called virus
      wet = ['wet', 'water', 'damp', 'moist', 'soaking'] #creates a list called wet
      charge = ['low', 'battery', 'charge'] #creates a list called charge
      headphones = ['3.5mm', 'headphone', 'jack'] #creates a list called headphones
      bent = ['bent', 'warped', 'arched'] #creates a list called bent
      sound = ['volume', 'quiet', 'loud', 'silent', 'speaker', 'sound', 'sounds'] #creates a list called sound
      frozen = ['frozen', 'stuck', 'stopped']
      exits = ['bye' 'exit']
      date = [] #creates an empty list called date
      today = datetime.date.today()
      date.append(today) #adds the current date to the list date
  
  
  ##    print("Welcome to tech support the date today is",date[0]) #prints welcome line and the date
  ##    sleep(2) #pauses the program for 2 seconds
      start = input("What is the problem with your phone? ") #creates an input for the user to state the problem
  
      questionL = start.lower() # changes the name of a variable and makes it lower case
  
      phrase = questionL.split() # splits up the phrase to help in later code
  
      for words in phrase: #checks to see if phrase is empty
          if words in smashed: #checks to see if words contains anything from the list smashed
              #os.system('ohdear.jpeg') #opens a picture in the default program
              #sleep(10) #pauses the program for 10 seconds
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[1])
                  sleep(1)
                  print(l[2])
                  sleep(5)
  
  
          elif words in wet:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[17])
                  sleep(1)
                  print(l[18])
                  sleep(1)
                  print(l[19])
                  sleep(5)
              pass
          elif words in wifi:
              with open('task 2 solutions.txt') as f:
                  l = []
                  os.system('tech.jpg')
                  sleep(4)
                  for lines in f:
                      l.append(lines)
                  print(l[4])
                  sleep(1)
                  print(l[5])
                  sleep(5)
              pass
          elif words in button:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[7])
                  sleep(1)
                  print(l[8])
                  sleep(5)
              pass
  
          elif words in temp:
              with open('task 2 solutions.txt') as f:
                  l = []
                  os.system('hot.gif')
                  sleep(7)
                  for lines in f:
                      l.append(lines)
                  print(l[10])
                  sleep(1)
                  print(l[11])
                  sleep(1)
                  print(l[12])
                  sleep(5)
              pass
  
  
              sleep(5)
              pass
  
          elif words in virus:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[14])
                  sleep(1)
                  print(l[15])
                  sleep(5)
              pass
  
          elif words in charge:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[21])
                  sleep(1)
                  print(l[22])
                  sleep(1)
                  print(l[23])
                  sleep(5)
              pass
  
          elif words in headphones:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[25])
  
              pass
  
          elif words in bent:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[27])
                  sleep(1)
                  print(l[28])
                  sleep(1)
                  print(l[29])
                  sleep(5)
              pass
  
  
          elif words in sound:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[31])
                  sleep(1)
                  print(l[32])
                  sleep(5)
              pass
  
          elif words in frozen:
              with open('task 2 solutions.txt') as f:
                  l = []
                  for lines in f:
                      l.append(lines)
                  print(l[34])
                  sleep(1)
                  print(l[35])
                  sleep(5)
              pass
          elif words in exits:
              exit()
  
  
          else:
              print("That solution is not covered by the program sadly but we have noted this down for the technition to deal with.")
  </code></pre>
  
  <p>This is the error I keep coming up with in Task 3:</p>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File "C:\Users\Alex\Downloads\Task 3 (1).py", line 35, in &lt;module&gt;
      task2.trouble2()
  NameError: name 'task2' is not defined
  </code></pre>