求问大佬们这个程序的错误在哪里
def binary(x):y = x//2
while 1:
r = x%2
y = x//2
x = y
num = '' + str(r)
if y < 1:
break
print(num)
一个十进制转二进制的函数,但是每次运行他只会进行一次循环是为啥呢?谢谢大佬们 啊是不是num哪里出问题了wwww def binary(x):
y = x//2
num=''
while 1:
r = x%2
y = x//2
x = y
num += str(r)
if y < 1:
break
num = num[::-1]
return '0b'+num def binary(x):
s = ''
while x:
s = str(x % 2) + s
x //= 2
return s
print(binary(int(input())))
页:
[1]