ReMedivh 2017-10-31 08:30 采纳率: 50%
浏览 2658

python基础题 如何把n进制转换为b进制

图片说明

  • 写回答

1条回答 默认 最新

  • cloudyzhao 2017-10-31 09:11
    关注

    m = int(input('please input the orginal number system'))
    n = int(input('please input the objective number system'))
    m_str = input('the orginal integer ')

    if(float(m_str)==int(float(m_str))):
    m_number = int(m_str,m)#get the numeric value of m
    symbol = ''

        if(m_number<0):#figure out the final symbol
                m_number = abs(m_number)#get positive value
                symbol = '-'
    
        if(n == 10):# m convert to 10
                print(symbol+str(m_number))
        else:#10 convert to n
                ans = ''
                while(m_number):
                        ans = str(m_number%n) + ans#doing the mod
                        m_number = m_number//n#warning!!: using // not /
                print(symbol+ans)#print the answer
    

    else:
    print('input is not integer')

    评论

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源