我想我正在計算從一個整數到二進制數的轉換錯誤。我輸入了整數6
並找回了二進制數0
,這是絕對錯誤的。你們能幫忙嗎?這是新的代碼。我不明白這個語法錯誤
def ConvertNtoBinary(n):
binaryStr = ''
if n < 0:
print('Value is a negative integer')
if n == 0:
print('Binary value of 0 is 0')
else:
if n > 0:
binaryStr = str(n % 2) + binaryStr
n = n > 1
return binaryStr
def main():
n = int(input('Enter a positive integer please: '))
binaryNumber = ConvertNtoBinary(n)
print('n converted to a binary number is: ',binaryNumber)
main()
這是如何與Windows相關的?並且自從什麼時候是'ValueError''' SyntaxError' ?! – ThiefMaster 2012-03-13 14:48:29