擅长:python、mysql、java
<p>第一件事:已经有一些东西正是你想做的,所以使用它是明智和有效的:</p>
<pre><code>for char in text:
bin(int(char))
</code></pre>
<p>我想,代码中的问题是您使用的是python3.x,其中整数之间的标准除法返回一个float(从[<a href="https://www.python.org/dev/peps/pep-0238/][PEP-0238]" rel="nofollow noreferrer">https://www.python.org/dev/peps/pep-0238/][PEP-0238]</a>开始)。
这里有一个建议,你应该如何改变你的功能,使它工作。您可以对照内置的<em>bin</em>功能进行检查:</p>
<pre><code>def decToBin(n):
wynik = ""
while n > 0:
wynik = str(n % 2) + wynik
n = n // 2
return wynik
</code></pre>