0

Trying to pass value from one function to another

function to input a number

def compute2():
    x=input("enter a number")
    num=int(x)
    print(num)
    return num

#function to find primes
def compute1(num):
    
   
   a = []
   for i in range(2,num+1):
     for j in range(2,i):
         
         if((i % j) == 0):
              
              break;
     else:
                 a.append(i)
   return a


#function for finding lcm
def compute(a):
     count=0
     
     
     b=[]
     
     for i in a:
           
           for j in range(1,20):
               if(i**j<20):
                   count=count+1
           b.append(count)
           count=0
     print(b)
     z=1
     for x in range(0,8):
         z= z * a[x]**b[x]
     print(z)
     return z      
                  
           
     
              
if __name__ == "__main__":
    compute2()
    compute1(num)
    compute(a)

I am getting the error 'num' not defined and 'a' not defined in the main function. I am trying to clear my basics. How to pass the argument and list

1
  • num=compute2() you have a return but you don't assign it to variable Commented Jul 12, 2019 at 17:52

1 Answer 1

1

num and a are local values to the functions. You are not defining them anywhere.

To achieve what you are trying to do,

num = compute2()
a = compute1(num)
compute(a)

or

compute(compute1(compute2()))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.