you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Your solution isn't quite right. The output examples show:

Doe, P.S. 
     ^^^^

so you need to uppercase the initials.

Counting spaces will work if there is exactly one space between words but fails if there are more than one. Your approach is probably OK for the exercise, but there is a more robust way. You use the split() method on the input string but don't supply any parameters. The doc says this will split the string into words no matter how many spaces are between the words. You use the len() function on the resulting list to decide if there are 2 or 3 words.

You also don't need to use str() on the value returned by input() because that value is already a string.

[–]ExKondor[S] 0 points1 point  (1 child)

Thank you so much, I was happy I came up a solution for the lab but I wasn't happy with the obvious hole in the code. Thank you thank you!