Jordan B.

asked • 09/23/17

Python spacing question

So this is my code, but when a name is input it doesn't have the spacing between the words, for example "M. Ghandi" comes out as "M.Ghandi" instead, how do I get the separation between the words?
 
name = input("Input a name: ")
first , second = name.split(",")
my_str = second[1].upper()
print(my_str + "." + first[0].upper() + first[1:])

Andy C.

class StrSpacing
{

public static void main(String args[])
{

String strDelim;

String strName = "M.Ghandi";

//matches any non word character
String [] tokens= strName.split("\\W");


String outbuff = " ";
for (int iLoop=0; iLoop<tokens.length; iLoop++)
{

outbuff = outbuff + tokens[iLoop] + " ";
}
System.out.println(outbuff);

}

}
Report

09/23/17

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.