无法将“列表”对象隐式转换为str

时间:2019-03-13 11:08:33

标签: python random

我有以下Python代码失败,并出现标题中所述的错误。为什么会发生这种情况,我该怎么做才能使代码正常工作?

endingsArray = ["ing","end","axe","gex","goh"]
student=int(input("Enter Number of Students"))
for i in range(0,len(endingsArray)):
    Name=str(input("Enter first three letters of name"))
    import random
    randomNo = random.randint(0,5)
    username=(Name + endingsArray)
    print(username)

1 个答案:

答案 0 :(得分:0)

我不知道你到底想要什么。但是我想当你想获得用户名+结尾时。您必须使用索引来调用该列表,例如:(对不起,我重新制作了您的代码)

endingsArray = ["ing", "end", "axe", "gex", "goh"]
    student = int(input("Enter Number of Students : "))
    for i in range(0, len(endingsArray)):
        randomNo = random.randint(0, 5)
        Name = str(input("Enter first three letters of name"))
        username = (Name + **endingsArray[i]**)
        print(username)

希望对您有帮助