python - How do you create a binary-Decimal conversion program? (format provided) -


i accidentally placed in programming class rather intro. computers. on head. know how this?

i need code decimal binary number conversion program in python (decimal number binary , vice versa). input program number , base. base can 2 or 10. if base 2, input binary number , output corresponding decimal number, vice versa.

the program first ask user input base , number in base. base can “b”, “d” or s. “b”, “d” indicates input binary number or decimal number, respectively , “s” stands “stop”. need check validation of input.

output format:

your output should follows:

please input base(b:binary, d:deciam, s:stop) b please input number 1101 13 please input base(b:binary, d:deciam, s:stop) d please input number 13 1101 please input base(b:binary, d:deciam, s:stop) input in not valid base please input base(b:binary, d:deciam, s:stop) b please input not valid binary number please input base(b:binary, d:deciam, s:stop) s 

dec bin:

s = bin(n)[2:] 

bin dec:

n = int(s, 2) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -