Q. During admission in a course, the names of the students are inserted in ascending order. Thus, performing the sorting operation at the time of inserting elements in a list. Identify the type of sorting technique being used and write a program using a user defined function that is invoked every time a name is input and stores the name in ascending order of names in the list.
Answer :-
You can use any sorting technique. Here we will bubble sorting technique.
def sorting ( lst ) : n = len(lst) for i in range(n): for j in range(0, n-i-1): if lst[j] > lst[j+1] : lst[j], lst[j+1] = lst[j+1], lst[j] return lst lst = [ ] while True : name = input("Enter the name of Student :- ") lst.append( name ) choice = input("Do you want to quit (Y/N) :-") if choice == "Y" or choice == "y" : break print("Sorted List :-", sorting( lst ))
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )