I'm trying to make this so that when a person types their name just the initials display capitalized and separated by a period. I can't figure out what is wrong with this code I wrote... help pls!
def main():
name = input('Type your name and press ENTER. ')
name_list = name.split()
print(name_list)
first = name[0][0]
second = name[1][0]
last = name[2][0]
print(first,'.', second,'.')
main()
If you are on Python 2.x you should exchange input for raw_input. Here's a quicker way to achieve what you're aiming for assuming you're on Python 2.x:
def main():
full_name = raw_input('Type your name and press ENTER. ')
initials = '.'.join(name[0].upper() for name in full_name.split())
print(initials)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With