# Pls with ALGORITHM LAB Problem

PROBLEM:

Create a function called binary_converter. Inside the function, implement an algorithm to convert decimal numbers between 0 and 255 to their binary equivalents.

For any invalid input, return string Invalid input

Example: For number 5 return string 101

TEST CASE:

``````import unittest

class BinaryConverterTestCases(unittest.TestCase):
def test_conversion_one(self):
result = binary_converter(0)
self.assertEqual(result, '0', msg='Invalid conversion')

def test_conversion_two(self):
result = binary_converter(62)
self.assertEqual(result, '111110', msg='Invalid conversion')

def test_no_negative_numbers(self):
result = binary_converter(-1)
self.assertEqual(result, 'Invalid input', msg='Input below 0 not allowed')

def test_no_numbers_above_255(self):
result = binary_converter(300)
self.assertEqual(result, 'Invalid input', msg='Input above 255 not allowed')
``````

MY SOLUTION:

``````def binary_converter(number_to_convert):
integer_division_result = 0
modulus_division_result=0
binary_divisor = 2
result = []
convertion=''
try:

assert (type(number_to_convert) is int),""

if number_to_convert == 0:
return str(number_to_convert)

elif number_to_convert < 0:
return "Invalid input"

elif number_to_convert > 255:
return "Invalid input"

else:
integer_division_result=number_to_convert//binary_divisor
modulus_division_result=number_to_convert % binary_divisor
result.insert(0,modulus_division_result)

while integer_division_result > 0:
number_to_convert = integer_division_result
integer_division_result=number_to_convert//binary_divisor
modulus_division_result=number_to_convert % binary_divisor
result.insert(0,modulus_division_result)

for binary_digit in result:
convertion += str(binary_digit)

return convertion

except AssertionError:
return "Invalid input"
``````

FEED BACK:
I KEEP GETTING ERROR IN YOUR CODE MSG!

So… what is the error message?