TypeError:“ str”和“ int

时间:2019-06-20 12:59:00

标签: python-3.6

当我使用python 2运行此代码时,没有问题。但是当我尝试使用python 3运行时,会引发错误: “ str”和“ int”的实例之间不支持“ TypeError:'>' 实际发生了什么?

number = int(input("Input Number : "))
if number < 0:
    raise ValueError("Number >= 0")
base = int(input("Input Base   : "))
if base < 2:
    raise ValueError("Base >= 2")
if number == 0:
    print("0")
    exit()
result_list = list()
modulo = 10

while modulo > 0:
    modulo = (number % base)
    number = (number // base)
    if modulo == 10:
        modulo = "A"
    elif modulo == 11:
        modulo = "B"
    elif modulo == 12:
        modulo = "C"
    elif modulo == 13:
        modulo = "D"
    elif modulo == 14:
        modulo = "E"
    elif modulo == "15":
        modulo = "F"
    result_list.insert(0,(str(modulo)))

print("".join(result_list))

0 个答案:

没有答案