I'm trying to get the function to work, it is suppose to convert Decimal to Binary but all it gives me different numbers instead. Like if I enter 12, it would give me 2. I'm not sure where in the code my issue is located. Any help would be great, thank you!
def decimalToBinary(value):
if value < 0: #Base case if number is a negative
return 'Not positive'
elif value == 0: #Base case if number is zero
return 0
else:
return decimalToBinary(value//2) + (value%2)
0xa,0b1010,0o12,10, etc). The output is a string that contains binary ("01") representation of the input integer. 2- usereturn '0'instead ofreturn 0if the input is0. 3- useraise ValueError('expected nonnegative integer')instead ofreturn 'Not positive'then you could useto_bin = lambda n: to_bin(n//2) + '01'[n%2] if n else ''for positiven