Sep-07-2019, 05:00 PM
I've wanted to write a program that converts an integer to it's binary equivalent. I'm getting an error saying Unbound Local Error. Local variable binary_string referenced before assignment. The last line in the while loop before the return statement is being flagged an error. I probably have other things wrong too if you see them please let me know.
I'm rather lost:
I'm rather lost:
def main(): x = int(input("Enter an integer: ")) binary_string = "" binary_string = decimal_to_binary(x) def decimal_to_binary(n): while(n > 0): remainder = n % 2 n = n / 2 binary_string = str(remainder) + binary_string return binary_string main()