0
I want to split a string, in the case of a binary number, to convert into octal and Hex, but I need to divide the inserted number into equal parts, in the case of octal, I would need to divide it 3 by 3. how can I do this in python 3.8. Ps: without using ready functions, I believe that by for or while I would, but I’m not sure. Please help me.
n = input("Binario:")
o = ""
for i in range(len(n)-2):
if(n[0+i]+n[1+i]+n[2+i] == "000"):
o = o + "0"
if(n[0+i]+n[1+i]+n[2+i] == "001"):
o = o + "1"
if(n[0+i]+n[1+i]+n[2+i] == "010"):
o = o + "2"
if(n[0+i]+n[1+i]+n[2+i] == "011"):
o = o + "3"
if(n[0+i]+n[1+i]+n[2+i] == "100"):
o = o + "4"
if(n[0+i]+n[1+i]+n[2+i] == "101"):
o = o + "5"
if(n[0+i]+n[1+i]+n[2+i] == "110"):
o = o + "6"
if(n[0+i]+n[1+i]+n[2+i] == "111"):
o = o + "7"
print(o)
I did so, but he takes values without having to take.
Hello @Marcusloureiro, do not put code picture, paste the code between three single inverted quotes (
código
)– Paulo Marques
This here maybe it helps (although it is with lists, with strings you can also use what is there).
– hkotsubo