[Python] Python simple base to base converter returns nothing as result [closed]

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a basic base to base converter. Basically the user enters a number, then enters the base he needs the number converted to, and the program converts the number. For example I enter Number? 0x10C, Base wanted? 10 and the program returns the result as 268.

    Here is my code:

    toConvertBase = int(input("Base wanted? "))
    if toConvertBase=="10":
    result=int(numberToConvert)
    print(result)
    elif toConvertBase=="2":
    result=bin(numberToConvert)
    print(result)
    elif toConvertBase=="16":
    result=hex(numberToConvert)
    print(result)


    I don't know what I am doing wrong here, but the program shows nothing as result:

    Enter a number? 0xCAFE
    Base wanted? 10


    Please help :)

    Continue reading...

Compartilhe esta Página