0

Having some trouble getting this to work... Basically I want to use the var binary (returned from inputF) in the convert function. I returned the variable, passed it in, and defined it... Stuck on what to do :/ I also defined it in main and passed it into the function... Says: Local variable 'binary' referenced before assignment.

def inputF():
  binary = input("Enter bin #: ")
  return(binary)

def convert(binary):
  binary = inputF(binary)
  print(binary)
  return

def main():
  binary = input(binary)
  inputF()
  convert(binary)
  return
main()
1
  • There's also a problem in convert(), the function inputF() does not take a parameter. Commented Dec 12, 2018 at 4:02

2 Answers 2

1

The error is coming in main because of the input(binary) statement (the error message should have included a line number pointing at that). If you want main to coordinate the inputF and convert functions, you can do:

def main():
    binary = inputF()
    convert(binary)

Then convert should just do whatever conversion it needs to do. Since you pass binary as an argument, you don't need to call inputF there:

def convert(binary):
    print(binary)
    # Do whatever you need to do

That way, convert doesn't need to worry about input at at all, and just processes the data passed to it as the argument.

Sign up to request clarification or add additional context in comments.

1 Comment

Amazing! Thanks :)
0

UnboundLocalError: local variable 'binary' referenced before assignment

This is because you are passing the variable binary before it's created.

something = input(binary)

What is the value of binary? (there isn't one).

How about:

binary = input("Enter value for 'binary'> ")

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.