[백준/python] 2745 진법변환

joseon0thing·2023년 8월 11일
0

python

목록 보기
10/17
post-thumbnail


a = input()
base = int(input())

int(a, int(base))

첫 번째 오류

코랩에서 출력은 됐으나 백준에서 틀림.
--> 조건이 맞지 않은 거 같음


두 번쨰 오류

while(True):
  a, base = input().split()
  base = int(base)
  if base < 2 and base > 36:
    print('재입력')
    continue
  else:
    print(int(a, base))
    break

36진수일 때는 출력이 됐으나 (조건인) 36 이상 혹은 2 이하일 때는 오류가(조건문을 통과함)
--> 2또는36인데 and로 조건을 설정함 (or로 수정)


최종 코드

while(True):
  a, base = input().split()
  base = int(base)
  if base < 2 or base > 36:
    print('재입력')
    continue
  else:
    print(int(a, base))
    break

profile
정리.velog

0개의 댓글