1

I'm not sure what to call this so I'll just explain what I need to do

Say I have the following script that gets a user inputs:

#test0.py

import functions

number = input('pick a number')
functions.dothis()

and this:

#functions.py
def dothis(): 
    global number
    if number == 1:
        print('the number is 1')
    else: 
        print('the number is not one')

this obviously shoots out 'number' is not defined.

How do I pass number into the dothis() function or am I going about this entirely the wrong way ?

cheers!

user1630350
  • 79
  • 3
  • 11

1 Answers1

1

Just pass it as an argument, like so:

def dothis(number): 
    if number == 1:
       ...

number = input('pick a number')
functions.dothis(number)
NPE
  • 486,780
  • 108
  • 951
  • 1,012