mercredi 27 février 2019

How do I randomly join the users input to strings stored in an array using random.choice

I need to write a program that will automatically generate unique usernames for students. The usernames have to be six characters long. The program should generate and display a list of student usernames. The program will ask how many usernames are to be generated. For each username, the first three letters of the student’s first name will be entered and then combined with a random ending from the list below: Ing, end, axe, gex, goh For a student with the first name David, the technician would enter Dav. The program will generate the username by RANDOMLY joining Dav to one of the endings. For example – Daving.

This is all I have so far, I would really appreciate it if anyone knows how to use random.choice to randomly combine the students first 3 letters of their name to the endings that are stored in the array. Thank you!

my code so far:

#Initialising the variables
usernames=0
usernameEndings=["ing", "end", "axe", "gex", "goh"]
studentsName=""
#Getting inputs
usernames=int(input("How many ``usernames are to be generated?"))
#proccess
for counter in range(0,usernames):
    studentsName = str(input("Please enter the first three letters of students name."))
        while len(str(studentsName)) <3 or len(str(studentsName)) >3:
        studentsName= str(input("ERROR, please re-enter the first three letters of students name."))




Aucun commentaire:

Enregistrer un commentaire