Home > OS >  Printing first letter of full name python
Printing first letter of full name python

Time:11-16

Hello I'm trying to create a program that takes input and prints out the initials all uppercase but I can't figure out why my program is only printing the first letter of the last item of the list after string is split

this is my code:

full_name = input("Please enter your full name: ")

name = full_name.split()

for item in name:
    new_name = item[0].upper()
    
print(new_name)

CodePudding user response:

You can make a new, empty variable like initials and add the first letter to it

full_name = input("full name: ")

name = full_name.split()

initials = ""

for item in name:
    initials  = item[0].upper()

print(initials)

CodePudding user response:

I think this can help you:

# get the full name from the user
full_name = input("Enter your full name: ")

# split the name into a list of words
name_list = full_name.split()

# loop through the list of words


for i in range(len(name_list)):
    # get the current word
    word = name_list[i]
    # uppercase the first letter of the word
    word = word[0].upper()   word[1:]
    # replace the word in the list with the new word
    name_list[i] = word


# join the list of words into a string
full_name = " ".join(name_list)

# print the full name
print(full_name)
  • Related