我的代码一直工作到插入第二个测试代码

2024-09-30 03:24:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我从下面的原始代码中进一步编辑了这段代码

ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def repr2dec(num, base):
    total = 0
    for ix, digit in enumerate(reversed(num)):
        total += ALPHA.index(digit) * base ** ix
    return total

print(repr2dec("23", 21) == 45)
print(repr2dec("11", 72) == 73)
print(repr2dec("43", 13) == 55)
print(repr2dec("AD", 15) == 163)

我当前的错误是:

Traceback (most recent call last):
  File "nt-test-6269e744", line 3, in <module>
    assert(convert.repToDecimal("23", 21) == 45)
AttributeError: module 'convert' has no attribute 'repToDecimal'

我相信我正朝着正确的方向前进,但我无法找到下一步的方向


Tags: 代码inalpha编辑convertbase方向num

热门问题