편집 기록

편집 기록
  • 프로필 김선우님의 편집
    날짜2018.04.12

    파이썬 기초 질문 ) 진수변환 프로그램 ) int() can't convert non-string with explicit base


    select= int(input("진수결정(16/10/8/2):"))
    num=input("값 입력:")
    
    if select !=2 and select != 8 and select != 16 and select != 10 :
         print("16,10,8,2 숫자 중 하나만 입력하세요")
         exit()
    
    elif select == 16:
         num10=int(num,16)
    elif select == 10:
         num10=int(num,10)
    elif select == 8:
         num10=int(num,8)
    elif select == 2:
         num10=int(num,2)
    
    
    print("16진수 ==>", hex(num10))
    print("10진수 ==>", num10)
    print("8진수 ==>", oct(num10))
    print("2진수 ==>", bin(num10))
    
    

    # num10="" (16=hex=str이니까?)_
    select= int(input("진수결정(16/10/8/2):"))
    num=int(input("값 입력:"))
    
    if select == 16:
         num10=int(num,16)
    elif select == 10:
         num10=int(num,10)
    elif select == 8:
         num10=int(num,8)
    elif select == 2:
         num10=int(num,2)
    else :
         print("16,10,8,2 숫자 중 하나만 입력하세요")
         exit()
    
    print("16진수 ==>", hex(num10))
    print("10진수 ==>", num10)
    print("8진수 ==>", oct(num10))
    print("2진수 ==>", bin(num10))
    
    

    어떤 식으로 고쳐야되고 어떤 부분에서 틀린건가요? 두 코드다 run안되는 이유를 모르겠숴여,,,

  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.04.05

    파이썬 기초 질문 ) 진수변환 프로그램 ) int() can't convert non-string with explicit base


    select= int(input("진수결정(16/10/8/2):"))
    num=input("값 입력:")
    
    if select !=2 and select != 8 and select != 16 and select != 10 :
         print("16,10,8,2 숫자 중 하나만 입력하세요")
         exit()
    
    elif select == 16:
         num10=int(num,16)
    elif select == 10:
         num10=int(num,10)
    elif select == 8:
         num10=int(num,8)
    elif select == 2:
         num10=int(num,2)
    
    
    print("16진수 ==>", hex(num10))
    print("10진수 ==>", num10)
    print("8진수 ==>", oct(num10))
    print("2진수 ==>", bin(num10))
    
    

    # num10="" (16=hex=str이니까?)_
    select= int(input("진수결정(16/10/8/2):"))
    num=int(input("값 입력:"))
    
    if select == 16:
         num10=int(num,16)
    elif select == 10:
         num10=int(num,10)
    elif select == 8:
         num10=int(num,8)
    elif select == 2:
         num10=int(num,2)
    else :
         print("16,10,8,2 숫자 중 하나만 입력하세요")
         exit()
    
    print("16진수 ==>", hex(num10))
    print("10진수 ==>", num10)
    print("8진수 ==>", oct(num10))
    print("2진수 ==>", bin(num10))
    
    

    어떤 식으로 고쳐야되고 어떤 부분에서 틀린건가요? 두 코드다 run안되는 이유를 모르겠숴여,,,