[CHALLENGE] Formate the names correctly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

[CHALLENGE] Formate the names correctly

write a program to do the following: for ex: the inputed person's name is "steve jobs", then we have to capitalize the first letters of the first name , surnames as well as the middle names. (other should be small) we have to keep the full surname, and only first letters of the first name and middle name with a "."(dot). few test cases: 1. steve jobs = S. Jobs 2. avay kumar nath= A. K. Nath 3. benidict cuMBerBATCH= B. Cumberbatch #display the output as well as change the original string too.

30th Oct 2017, 12:51 PM
Sudipta Kumar Nath
Sudipta Kumar Nath - avatar
11 Answers
+ 3
C# has special function for that: CultureInfo.CurrentCulture.TextInfo.ToTitleCase(string) Then it just needs to take first letters. Full code: https://code.sololearn.com/cZ35CmjDRE36/#cs
30th Oct 2017, 2:57 PM
Andrei Zhulid
+ 12
JavaScript: var a = prompt("").trim().split(" "); alert(a.slice(0, a.length - 1).reduce(function(a, b) { return a + b.charAt(0).toUpperCase() + ". "; }, "") + a[a.length - 1]);
30th Oct 2017, 1:01 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
Thanks for the challenge. Here's my try : https://code.sololearn.com/c8piyQCxKrhl/?ref=app
31st Oct 2017, 2:04 PM
LukArToDo
LukArToDo - avatar
+ 7
python i = input().title().split() print(*[i[j][0]+'.' for j in range(len(i)-1)], i[-1])
30th Oct 2017, 2:11 PM
Kartikey Sahu
Kartikey Sahu - avatar
30th Oct 2017, 3:38 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 5
@Sudipta check properly
8th Nov 2017, 7:04 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 2
@kazi your code is fine. but it is not satisfying case 3 other letters also should be converted to small letter. except the first letters.
30th Oct 2017, 5:32 PM
Sudipta Kumar Nath
Sudipta Kumar Nath - avatar
+ 2
I coded a thing! (Not sure how to post, either, ohno...) https://code.sololearn.com/cStl2P64Frp1/?ref=app
1st Nov 2017, 7:33 PM
Stephanie
+ 1
@Krishna Teja Yeluripati Your code will not be working because the code doesn't process extra spaces and doesn't capitalize the last name. Just FYI ;)
30th Oct 2017, 3:00 PM
Andrei Zhulid
30th Oct 2017, 6:24 PM
VcC
VcC - avatar
0
@kazi its correct now
8th Nov 2017, 7:20 AM
Sudipta Kumar Nath
Sudipta Kumar Nath - avatar