8.1 Binary representation of a decimal number between 0 and 31 by playing musical notes

Python solution

View solution

This is just one of many possible solutions:

decimal_number = int(input('Please enter a decimal number between 0 and 31: '))
bit_value = 32
while bit_value > 1:
  bit_value = bit_value / 2
  if decimal_number >= bit_value:
    print('high')
    decimal_number = decimal_number - bit_value
  else:
    print('low')

Back to programming challenge