将碱基转换为2到9以内的碱基

Convert base to bases within 2 to 9

好吧,我迷路了,一直在思考如何取得进一步的进展。 该程序将 return 用户输入的 base 的值放入这样的列表中 [1, 2, 2]。 我正在尝试做两件事。首先,而不是像

这样的单个数字
userInt = 50

我希望能够输入

userList = [50, 3, 6, 44]

然后让公式将每个数字转换为正确的基数。

因此,如果我将其转换为以 6 为底数,我希望结果为:

userNewList = [122, 3, 10, 112]

我已经用 for 循环试过了,但无法正确完成,最后遇到了一个 int is not iterable type 错误。

def baseConversion(userInt, base):
    remList = []
    while(userInt > 0):
        remList.append(userInt % base)
        userInt = userInt // base     
    return (remList[::-1])       


def main():
    base = int(input('Enter a base: '))
    userInt = 50
    remList = baseConversion(userInt, base)
    baseConversion(userInt, base)
    print(remList)
main()

感谢您提供的任何帮助。

使用Python 2.7,但你可以理解:

>>> def baseConversion(userInt, base):
        remList = ''
        while(userInt > 0):
            remList += str(userInt % base)
            userInt = userInt // base
        return int(remList[::-1]) # If you are just printing, you don't need to convert to int.

>>> def main():
        base = int(raw_input('Enter a base:'))
        userInt = [int(s.strip()) for s in raw_input('Enter numbers (comma separated):').split(',')]
        result = [baseConversion(i, base)  for i in userInt]
        print result


>>> main()
Enter a base:6
Enter numbers (comma separated):50,3,6,44
[122, 3, 10, 112]