정수에서 2 진수로의 변환을 잘못 계산하고 있다고 생각합니다. 정수 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