8.2 Binary representation of any decimal number 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: '))
bit_value = 1
while bit_value <= decimal_number:
  bit_value = bit_value * 2
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

Extra Challenge

Modify your program so it would play a low note when the user enters the number zero as the input.