Code works in Windows, but not on Mac
<p>So I'm new to programming, and recently I got an assignment to create a program that could convert binary to decimal and vice versa, and also decimal to hexadecimal and vice versa. The problem is, I'm not allowed to use available functions such as <code>int()</code> or <code>hex()</code> or <code>bin()</code>.</p>

<p>I might have found a way to do the conversion from decimal to binary, and I tried it out on my friends' laptop (which runs on Windows) and it worked. But when I tried to execute it in my own laptop (a MacBook), it won't run even though it's the exact same code. Here's the code:</p>

<pre><code>def dectobin(x):
    temporary_result = ""
    while x &gt; 0:
        result = str(x % 2) + temporary_result
        x = x // 2
    return result
</code></pre>

<p>Instead of the result being the binary number, it just returns the value of <code>x % 2</code>. Does anyone have any idea why it does that on a Mac and not on Windows? And if so, where did I go wrong? How do I fix it?</p>

<p>Why do you need temporary_result when the value never changes within your loop?  </p>

<pre><code>def dectobin(x):
result = ""
while x &gt; 0:
    result = str(x % 2) + result
    x = x // 2
return result
</code></pre>

python windows osx python-3.x