I'm calculating the conversion from an integer to a binary number wrong. I entered the integer 6 and got back the binary number 0. which is definitely wrong. Can you guys help out? I'm using python 3 by the way.
def ConvertNtoBinary(n):
binaryStr = ''
if n < 0:
print('Value is a negative integer')
if n == 0:
print('Binary value of 0 is 0')
else:
if n > 0:
binaryStr = str(n % 2) + binaryStr
n = n > 1
return binaryStr
def main():
n = int(input('Enter a positive integer please: '))
binaryNumber = ConvertNtoBinary(n)
print('n converted to a binary number is: ',binaryNumber)
main()
bin(). (You may need to strip off the leading0bfrom the result, depending on your purposes.)