
Jordan B.
asked 09/23/17Python 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:])
my_str = second[1].upper()
print(my_str + "." + first[0].upper() + first[1:])
More
1 Expert Answer

Andy C. answered 09/23/17
Tutor
4.9
(27)
Math/Physics Tutor
You are using the comma as the delimiter.
Try name.split(" ");
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.
Andy C.
{
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);
}
}
09/23/17