4 Replies - 666 Views - Last Post: 28 February 2014 - 09:41 PM Rate Topic: -----

#1 Kassonhe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 14

Read a person's first and last names and display their initials.

Posted 19 February 2014 - 02:28 PM

So far all I have is this:


name = input("Enter first and last name: ")
newName = name.upper()
words = newName.split()
Is This A Good Question/Topic? 0
  • +

Replies To: Read a person's first and last names and display their initials.

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9044
  • View blog
  • Posts: 33,951
  • Joined: 12-June 08

Re: Read a person's first and last names and display their initials.

Posted 19 February 2014 - 02:30 PM

... okay, so what do you think? Perhaps use the nature of a string as an array and look at the first index character of each?
Was This Post Helpful? 0
  • +
  • -

#3 Kassonhe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-February 14

Re: Read a person's first and last names and display their initials.

Posted 19 February 2014 - 03:09 PM

Okay so I've got this now:
name = input("Please Enter Your First and Last Name: ")
    name_split = name.split()
    print(name_split)
    outputStr = ""
    for line in name_split:
        outputStr = outputStr + line[0][0].upper() + '.'

    print('.'.join([c[0].upper() for c in name_split]))

I don't know how to put a comma between the initials, like if I was doing more than one name.

This post has been edited by andrewsw: 19 February 2014 - 04:52 PM
Reason for edit:: Please use code tags

Was This Post Helpful? 0
  • +
  • -

#4 DK3250  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 102
  • Joined: 27-December 13

Re: Read a person's first and last names and display their initials.

Posted 20 February 2014 - 05:48 AM

Your last print statement should just be:
print(outputStr)

If you want to separate more than one set of initials, you first need to decide on the input format. Should full name input be separated by comma or otherwise...
After inputing multiple names, you need to decide how to split the names and handle them separately.
Was This Post Helpful? 0
  • +
  • -

#5 GavinDser  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-January 14

Re: Read a person's first and last names and display their initials.

Posted 28 February 2014 - 09:41 PM

what you can do is that you make the person type the name with space in it, for example: Smith Code
and u can first take the first letter, which is [0] in this case, then find the space using .find(), and the result of .find(), which we can call r, could use for the second initial ------ [r+1], combining all these together you would have the initial
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1