Homework
Below is an example of decimal number to binary converter which you can use as a starting template.
def DecimalToBinary(input):
if 0 <= input <= 255:
pass
else:
print(int(input) + "Intentional Error to Restart Loop")
i = 7
binary = ""
while i >= 0:
if input % (2**i) == input:
binary += "0"
i -= 1
else:
binary += "1"
input -= 2**i
i -= 1
return binary
# function to reverse the string
def reverse(strs):
print(strs[::-1])
# Driver Code
num = 67
print("The reverse of 67 in binary is:", end=" ")
reverse(DecimalToBinary(num))
# input box
def getUserInput():
try:
userinp = int(input("Input an integer between 0 and 255."))
userbin = DecimalToBinary(userinp)
print('"' + str(userinp) + '" in binary is "' + userbin + '".')
except:
print("Invalid input.")
getUserInput()
getUserInput()