UserName Generator Python

时间:2016-05-13 19:32:57

标签: python python-3.x

这是我的代码:

from random import randint 
for i in range(5): 
    FN = (input("What is your name?"))
    firstletter = FN[:1] 
    SN = []
    first3letters = SN[:3]
    x = str(len(SN))
    sentence = str(randint(0,9))+(first3letters.lower())+(firstletter.upper()+(x))
    print(sentence)

我一直在努力,我需要将5个用户名生成一个数组 - 但我对如何做到这一点感到困惑,是否有人能够提供帮助?

1 个答案:

答案 0 :(得分:2)

尝试将x = len(SN)更改为x = str(len(SN))

对于循环,您需要在循环中缩进代码。接受的语法是四个空格,所以:

from random import randint

sentences = []
for i in range(5):
    FN = (input("What is your name?"))
    firstletter = FN[:1]
    SN = []
    SN = (input("What is your last name?"))
    first3letters = SN[:3]
    x = str(len(SN))

    sentence = str(randint(0,9))+(first3letters.lower())+(firstletter.upper()+x)
    print(sentence)
    sentences.append(sentence)