Get a List of Name as an Input From The User And Make The First Letters in Caps And Print Each Word as a List

Hi, in this article you will learn a python program to modify the names having first letter as capital letter.

Lets ask user to enter names and convert the names.

 

Get a List of Name as an Input From The User And Make The First Letters in Caps And Print Each Word as a List

 

 


Get a List of Name as an Input From The User And Make The First Letters in Caps And Print Each Word as a List

Take a integer variable length, ask a user to enter number of names using input() function call. Take empty list of strings and iterate until list length and ask user to enter names and fill the list of strings.

length = int(input("Enter Number of Names : "))
names = []
for index in range(length):
   temp = input(f"Enter Names #{index+1} : ")
   names.append(temp)




Using the for loop iterate and enumerate the list of strings, get the name and index. Replace the list index item by modifying the first letter of string to upper case as whoule below and append the remaining characters.

for index, name in enumerate(names):
   names[index] = name[0].upper() + name[1:]




Use the print() function call print the list containing the names.

print("Names present in list are ...")
for name in names:
   print(name)




Python Program
====================

length = int(input("Enter Number of Names : "))
names = []
for index in range(length):
   temp = input(f"Enter Names #{index+1} : ")
   names.append(temp)

for index, name in enumerate(names):
   names[index] = name[0].upper() + name[1:]

print("Names present in list are ...")
for name in names:
   print(name)





Output
====================
Enter Number of Names : 3
Enter Names #1 : jhon
Enter Names #2 : mary
Enter Names #3 : james
Names present in list are ...
Jhon
Mary
James




Output
================
Enter Number of Names : 5
Enter Names #1 : albert
Enter Names #2 : sam
Enter Names #3 : jimmy
Enter Names #4 : tomy
Enter Names #5 : adams
Names present in list are ...
Albert
Sam
Jimmy
Tomy
Adams





Conclusion
====================
Execute the above python program by providing the random names as input to python program.

Comment it down below if you have any queries related to above python program.


Post a Comment

0 Comments