-1
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)

I need to make an array, which will be printed and consist of the 5 usernames which get generated with this code. How would I do that?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

Convert firstletter and first3letters into a string before using lower() and upper().

from random import randint 
for i in range(2): 
    FN = input("What is your name? ")
    firstletter = ''.join(FN[:1])

    SN = 'bMwGermany'
    first3letters = ''.join(SN[:3])
    x = str(len(SN))

    # sentence = str(randint(0,9))+(first3letters.lower())+(firstletter.upper()+(x))
    sentence = ''.join([str(randint(0, 9)), first3letters.lower(), firstletter.upper(), x])
    print(sentence)

# Test
$ python3 stackoverflow.py 
What is your name? hello
1bmwH8
What is your name? world
9bmwW8

Note that for Python2, use raw_input instead of input. Refer to Python input() error - NameError: name '…' is not defined for the detailed description.

Community
  • 1
  • 1
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134