I'm trying to create multiple user with a for loop. In the code I want the "i" in Useri to be replaced by the value of i so that I can create User1, User2 and so on.
for i in range(x,y):
Useri="Joy Smith"
I'm trying to create multiple user with a for loop. In the code I want the "i" in Useri to be replaced by the value of i so that I can create User1, User2 and so on.
for i in range(x,y):
Useri="Joy Smith"
You should opt to create a list
of users:
userList = [] # empty list
for i in range(1,6): # iterate over a range
userList.append("User" + str(i)) # append the users into the list
print(userList)
OUTPUT:
['User1', 'User2', 'User3', 'User4', 'User5']
EDIT:
If you want the Users
to have a name then you my create a list
of perhaps, names
as well.
userList = []
name = ['Joy Smith', 'Oliver Kahn', 'Alex Jay', 'Emkay Kay', 'Alexa Smith', 'Nitro Cage']
for i in range(1,len(name)):
userList.append("User" + str(i) + ": " + name[i])
print(userList)
OUTPUT:
['User1: Oliver Kahn', 'User2: Alex Jay', 'User3: Emkay Kay',
'User4: Alexa Smith', 'User5: Nitro Cage']