代码拉取完成,页面将自动刷新
def baseconvert_dectobinoroct():
list_empty = []
a = int(input("请输入一个自然数:"))
b = int(input("请输入转化的进制(输入1至9中的一个进制基数):"))
remainder = a % b # 余数
quotient = (a - remainder) / b # 商
while quotient != 0:
list_empty.append(int(remainder))
a = (a - remainder) / b
remainder = a % b
quotient = (a - remainder) / b
else:
list_empty.append(int(remainder))
list_answer = list_empty[::-1]
d = ''
for i in range(len(list_answer)):
c = list_answer[i]
d = str(d) + str(c)
print(d)
def baseconvert_dectohex():
dict1 = {"0": 0, "1": 1, "2": 2, "3": 3,
"4": 4, "5": 5, "6": 6, "7": 7,
"8": 8, "9": 9, "10": 'A', "11": 'B',
"12": 'C', "13": 'D', "14": 'E', "15": 'F'}
list_empty = []
a = int(input("请输入一个自然数:"))
b = 16
remainder = a % b # 余数
quotient = (a - remainder) / b # 商
while quotient != 0:
list_empty.append(dict1[str(int(remainder))])
a = (a - remainder) / b
remainder = a % b
quotient = (a - remainder) / b
else:
list_empty.append(dict1[str(int(remainder))])
list_answer = list_empty[::-1]
d = ''
for i in range(len(list_answer)):
c = list_answer[i]
d = str(d) + str(c)
print(d)
baseconvert_dectobinoroct()
baseconvert_dectohex()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。