I'm trying to replace a value entered by a user with a string to make the output cleaner
I thought an if statement would help, but I'm not sure how it would tie in with my intended output
def main() :
number = int(input("Enter your number: "))
base = int(input("Convert to\n" \
" Binary[2] - Octal[8] - Hexadecimal[16]: "))
if base == 2 :
"binary"
elif base == 8 :
"octal"
else:
"hexadecimal"
print("\n"+str(number) +" in "+ str(base) + " is: " + str(convert(number, 10, base)))
def convert(fromNum, fromBase, toBase) :
toNum = 0
power = 0
while fromNum > 0 :
toNum += fromBase ** power * (fromNum % toBase)
fromNum //= toBase
power += 1
return toNum
main()
What I'm trying to get: if user enters 5 as their number and 2 as conversion. Output would be: "5 in binary is: 101"