-1

I'm trying to create a program that will take a user's input, such as a URL that contains numbers, symbols, and letters and converts it into a string of binary. I've tried looking up string to binary using Python on here but so far they all seem outdated using Python 2.x instead of Python 3.x. I want it to show something like:

Enter a string to convert: http://www.google.com/ 01101000011101000111010001110000001110100010111100101111011101110111011101110111001011100110011101101111011011110110011101101100011001010010111001100011011011110110110100101111

Then stores that binary string to convert back to http://www.google.com/

I tried making a function called getInput to get user input, then returning that value to pass to another function called toBinary, but when I try to pass the returned string it gives me an error saying the argument is not defined.

Example:

def getInput():  
    x = input(str(Enter a string to convert: ))  
    return x

def toBinary(x):  
    #convert to binary  
    #print binary  
    return x

def toString(x)  
    #convert binary to string  
    #print string  
    return

getInput()  
toBinary(x)  
toString(x)  

Thank you in advance!

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Kyle
  • 1
  • 1
  • related: [Convert Binary to ASCII and vice versa (Python)](http://stackoverflow.com/q/7396849/4279) – jfs Oct 03 '14 at 06:49

1 Answers1

0

Note that variables have local scope inside functions ! if you want to pass x to toBinary(x) you can store getInput in a global variable and the pass it to toBinary !

x=getInput() 

def toBinary(x) :

#other part of function
Mazdak
  • 105,000
  • 18
  • 159
  • 188