-1
저는 프로그래밍에 새로운 것이므로 숙제를 위해 숙제를 위해 바이너리 변환기에 denary를 입력해야합니다. 이 코드를 실행하면 나는 다음과 같은 오류가 발생합니다 :Python 3.4.2 IDLE : 'denaryInput'을 정의 할 때 오류가 발생했습니다.
if denaryInput < 0:
NameError: name 'denaryInput' is not defined
내가 잘못하고 있어요 및 답변 주시면 감사 것을 확신입니다. 사용
코드 :
"""We are asking the user for a number"""
def getNumber():
denaryInput = int(input("Please enter a number between 0 and 255: "))
"""We are validating the number"""
def validateNumber():
if denaryInput < 0:
print("Error: Number is too small, try again!" + " \n")
return False
elif denaryInput > 255:
print("Error: Number is too big, please try again!" + " \n")
return False
else:
return True
def binaryNumber():
result = []
for number in range(8):
bit = denaryInput % 2
result.append(bit)
denaryInput = denaryInput // 2
result.reverse()
str1 = "".join(str(x)for x in result)
print (str1 + " \n")
"""Now telling the computer to run the code above and in what order of operations"""
def mainProgram():
answer = getNumber()
validNum = validateNumber()
Binary = binaryNumber()
print("The binary equlivent for that number is " + Binary + " \n")
mainProgram()
가변적으로 getNumber 함수의 로컬 범위에만 존재합니다. –
도움을 주셔서 감사합니다. 현재 작동하고 있습니다. – rskw00