1

I'm trying to turn a full name into just the initials from one string. My logic is to capitalize all the names in the string, break the string by the spaces into a list, then select the first character of each index, then join the characters into a single string divided by periods.

I'm having trouble with this and not sure if there's a better way.

Here's my current progress:

def main():
    fstn= input("Enter your full name:")

    fstn=fstn.title()
    fstn= fstn.split(" ")
    for i in fstn:
        fstn= i[0]
        print(fstn)


main()

This prints out each initial on a different line, how would i finish this?

Bahrom
  • 4,752
  • 32
  • 41
  • Possible duplicate of [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) – Kevin Oct 13 '17 at 15:51

2 Answers2

2
def main():
    fstn= input("Enter your full name:")
    print ('.'.join(word[0] for word in fstn.split(" ")).upper()) #for python 3


main()
scharette
  • 9,437
  • 8
  • 33
  • 67
galaxyan
  • 5,944
  • 2
  • 19
  • 43
0

Hi check this example out,

def main():
    fstn= input("Enter your full name:")
    fstn=fstn.title()
    fstn= fstn.split(" ")
    out_str = ""
    for i in fstn:
        out_str = out_str + i[0] + "."
    print(out_str)

main()
Stack
  • 4,116
  • 3
  • 18
  • 23