1 Star 0 Fork 0

杨谨徽/代码托管

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
进制转化 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
杨谨徽 提交于 2021-11-01 21:56 +08:00 . add 进制转化.
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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SHIBATORI/code-hosting.git
git@gitee.com:SHIBATORI/code-hosting.git
SHIBATORI
code-hosting
代码托管
master

搜索帮助