Q. The Investiture Ceremony is a prestigious event in every school's calendar wherein the school formally entrusts responsibilities on the 'young student leaders.
At MySchool, the list STL stores the names of all the students of class XI who have applied for the various School Leaders posts. Out of these, school leaders will be selected.
Students need to register their name through an online application form available on school's website. Ideally the name should be in the form such that First name and Last name have their first letter capitalized and rest of the letters in lowercase.
But not all students are careful when entering their names, so the names can appear with incorrectly capitalized letters.
For example :-
STL = [ "Meesha Jain", "khushi khan", "Raman Singh", "yashi Sheril"]
Write a program that provides functions for :-
(i) selecting only those correctly entered entries where the first letters of the first name and last name are capitalized.
(ii) selecting only the incorrectly entered names.
(iii) returning a list with corrected names.
Answer :-
def select_errors (STL): newList = [] for record in STL: name_surname = record.split(' ') name = name_surname[0] surname = name_surname[1] if name[0].islower() or surname[0].islower(): newList.append(record) return newList def select_correct (STL): newList = [] for record in STL: name_surname = record.split(" ") name = name_surname[0] surname = name_surname[1] if not name[0].islower() and not surname[0].islower(): newList.append(record) return newList def correct_entries (STL): newList = [] for record in STL: name_surname = record.split(' ') name = name_surname[0] surname = name_surname[1] newList.append(name.capitalize()+ ' ' + surname.capitalize()) return newList STL = [] ch = 0 while (ch != 4): print("\t ------") print("\t| MENU |") print("\t ------") print("1. Apply for the School Post") print("2. List of all applicants") print("3. Correct the Incorrect Entries") print("4. Exit\n") ch = int(input("Enter your choice (1-4): ")) if ch == 1: name = input("Enter your name: ") STL.append (name) elif ch == 2 : print("Students applied so far: ") print (STL) elif ch == 3 : ok_entries = select_correct(STL) error_entries = select_errors(STL) corrected_entries = correct_entries(STL) print("Correctly entered names:", ok_entries) print("Incorrectly entered names:", error_entries) print("Corrected names:\n", corrected_entries) elif ch != 4: print("valid choices are 1...4: ") else: print("THANK YOU")
Output :-
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 1
Enter your name: Path walla
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 1
Enter your name: Computer Portal
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 1
Enter your name: Portal Express
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 2
Students applied so far:
['Path walla', 'Computer Portal', 'Portal Express']
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 3
Correctly entered names: ['Computer Portal', 'Portal Express']
Incorrectly entered names: ['Path walla']
Corrected names:
['Path Walla', 'Computer Portal', 'Portal Express']
------
| MENU |
------
1. Apply for the School Post
2. List of all applicants
3. Correct the Incorrect Entries
4. Exit
Enter your choice (1-4): 4
THANK YOU
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )