嗨,你能帮我把denary值转换成二进制和十六进制吗?我必须输入0到15之间的数字,输出应该是十六进制和二进制等价.这是我到目前为止所做的:
denary_list= ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"]
print("denary list")
binary_list=["0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"]
print("binary list")
hex_list=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
print("hex list")
option=input("enter choice:\n1.print values\n2.convert denary number to binary and hex\n3. Convert a hex value between 0 and 15 to denary or binary value\n9. Quit")
if option=='1':
print ("denary","\t","binary","hex")
count1=0
while count1<len(denarylist) and count1<len(binarylist) and count1<len(hexlist):
print(denarylist[count1],"\t",binarylist[count1],"\t",hexlist[count1])
count1+=1
if option=='2':
number=int(input("what number do you choose to convert to binary and hex"))
if number<=15 and number>=0:
Run Code Online (Sandbox Code Playgroud)