I was trying to do a task set by my friend (below) to help with my knowledge and I ran into a problem. I need to sort an array alphabetically, yet I cannot find anything anywhere to help with the problem. I have tried to use some sorting code that I have found, but that is for when the coder knows the inputs. However, because the user enters the inputs into an array I do not know how to proceed. The code and the task are below.
"Create a program that will let a teacher enter between 20-30 students( must be onput validation) once all 20-30 students entered make them in to an array with their last names deciding whether they are at the front or back of the register."
print ("Title: School Register")
print ("Date: 25/01/2022")
pupilNumber = int(input("How many pupils are in your class?"))
while pupilNumber < 20 or pupilNumber > 30:
print ("That is not a valid number of pupils, please re-enter your number of pupils.")
pupilNumber = int(input())
pupilName = [""]*pupilNumber
for counter in range (0, pupilNumber):
pupilName[counter] = str(input("Enter your pupils last names in alphabetical order."))
print ("The first person on the register is", pupilName[0])
print ("The last person on the register is", pupilName[counter])