Hello everyone, welcome to the Python tutorial In this tutorial, I'm going to set up a list of students who can graduate I would first have a list of students who cannot graduate And then I will let the user enter some student names And from those names entered, the computer would generate the student list who are able to graduate OK, let us do the implementation Suppose I have a black list of students who cannot graduate OK, these four students cannot graduate for some reasons.
For example, they fail an examination And then I will let the user input the names of other students And I would like to check whether those students entered are able to graduate So I would let the user input a number of students So I set the number of students to be entered like this.
In this case, the number of students are entered by the user And then I will use num_students to store the number of students that are going to be input to the system Then I will create a list to store the student names that are going to be received And I would set up a white list that stores the names that the students can graduate So for the student list and the white list, they are now empty lists for the time being.
And I will put the student names to the.
to the student list.
And I will put the names who are able to graduate to the white list Since I already.
already know the number of students to be received from the user input, I can use a for loop to allow the user input Suppose the name is stored in the variable called prompt If I want to check whether a user has really entered the student name I can do something like this If the user prompt is an empty string, that means if the user is not able to give a student name to the system, I would have something like this I would urge the user to input a non-empty name, so that when the user wants to save the names of five students, I would really urge the user to give exactly five names If the prompt is not an empty string, I would simply append the name received from the user input to the student list So at that time, the student list here will no longer be an empty list after I have received and stored the student names from the user, I would do the checking here I would pick up a student name from the student list that I created a previously Here is the idea of the blacklist checking If I have received the student names from the user input, I want to check each of the students in the student list.
And I would like to see whether there is a student being in the blacklist already If the student is actually not in the blacklist, I would append student name to the white list.
So the white list will store the student name who are able to graduate After the completion of for loop, I can simply print out that the students in the white list, which means those who are able to graduate OK.
First I would like to print out the number of students who are able to graduate So I simply return the length of the white list Since length of a white list is an integer, I would like to change it to a string before I can do the concatenation with other strings OK.
And the last line of code here, I will sort the white list first in alphabetical order And then I will print out every name stored in the white list by using a separator being the newline character So I would print out the names one line by one line So let us see the result of the code here Suppose I have 5 students The first name is for example Peter The second name is an empty string So you see, I have to enter an.
a non-empty name.
So I can input input Carol The third one is Susan The fourth one is Robert.
And the fifth one can be Ivy And then from what I have input, I can return the three student who are able to graduate It means that Carol, Ivy, and Peter are not in the blacklist And for those who are in the blacklist, like Peter and.
Sorry, like Susan and Robert, they are not allowed they are not allowed to graduate.
So I won't print out their names My implementation is quite straightforward and intuitive, but it may not be the best version or the most efficient approach If you can think about any improvement of my code, feel free to post your improvement on the comment section below the video If you like this video, please give me a like and please subscribe to my channel as well Thank you for watching.