Binary converter alogrithim
<p>Create a function called binary_converter. Inside the function, implement an algorithm to convert decimal numbers between 0 and 255 to their binary equivalents.</p>

<p>For any invalid input, return string Invalid input</p>

<p>Example: For number 5 return string 101</p>

<p>my code</p>

<pre><code>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')
</code></pre>

<p>code has error pls i'm new to programming, home study actually</p>

<p>Edited
code </p>

<pre><code>def binary_converter(n):
    if(n==0):
        return "0"
    elif(n&gt;255):
        print("out of range")
        return ""
    else:
        ans=""
        while(n&gt;0):
            temp=n%2
            ans=str(temp)+ans
            n=n/2
        return ans
</code></pre>

<p>Error report</p>

<p>THERE IS AN ERROR/BUG IN YOUR CODE</p>

<blockquote>
  <p>Results:  {"finished": true, "success": [{"fullName":
  "test_conversion_one", "passedSpecNumber": 1}, {"fullName":
  "test_conversion_two", "passedSpecNumber": 2}], "passed": false,
  "started": true, "failures": [{"failedSpecNumber": 1, "fullName":
  "test_no_negative_numbers", "failedExpectations": [{"message":
  "Failure in line 19, in test_no_negative_numbers\n<br>
  self.assertEqual(result, 'Invalid input', msg='Input below 0 not
  allowed')\nAssertionError: Input below 0 not allowed\n"}]},
  {"failedSpecNumber": 2, "fullName": "test_no_numbers_above_255",
  "failedExpectations": [{"message": "Failure in line 23, in
  test_no_numbers_above_255\n    self.assertEqual(result, 'Invalid
  input', msg='Input above 255 not allowed')\nAssertionError: Input
  above 255 not allowed\n"}]}], "specs": {"count": 4, "pendingCount": 0,
  "time": "0.000112"}} out of range</p>
</blockquote>

<p>Try this code... </p>

<pre><code>def binary_converter(n):
    if(n==0):
        return "0"
    elif(n&gt;255):
        print("out of range")
        return ""
    else:
        ans=""
        while(n&gt;0):
            temp=n%2
            ans=str(temp)+ans
            n=n/2
        return ans
</code></pre>

python