온라인 학습 플랫폼을 통해이 질문을하고 있는데, 내가 통과해야하는 테스트 케이스가 있습니다. 주제는 Higher Order Functions입니다.십진법을 모든 기본 언어로 변환하는 기능
숫자 n은 1 < N < (17)을 수용하고베이스 N의로 특정 진수로 변환하는 다수의 변환기를 반환하는 함수 make_decimal_to_n_ary_converter 쓰기 : 여기
질문이다. 다음은
내 코드이다 (I는 내부 기능, 즉 변환기를 사용하기로하고 (X))
def make_decimal_to_n_ary_converter(n):
def converter(x):
if x==0 or x==1:
return x
i=x
b=('A','B','C','D','E','F')
result = ""
while i>0:
a=i%n #3
if a<10:
result = str(i%n)+result
else:
d=a-10
result = b[d] + result
i=i//n
return result
return converter
#Lines below are not to be changed, part of qn
decimal_to_binary = make_decimal_to_n_ary_converter(2)
decimal_to_octal = make_decimal_to_n_ary_converter(8)
decimal_to_hexadecimal = make_decimal_to_n_ary_converter(16)
여기 내 코드가 전달 몇 가지 테스트 케이스입니다
decimal_to_binary가 (212) 516,decimal_to_hexadecimal (213)
D5
make_decimal_to_n_ary_converter (15) (213)
E3
그러나 내 코드 일부 전용 테스트 케이스를 실패하고 난 수신 된 피드백은 while 루프 내 로직은 잘못된이었다. 그러나 일부 숫자를 인쇄 한 후에는 잘못된 것을 보지 못했습니다. 도움을 주시면 고맙겠습니다. 감사합니다.