Click here to Skip to main content
15,560,542 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Take the input of a name and print its abbreviation after the last name. For example, if I input,Sachin Ramesh Tendulkar, it will output Tendulkar SR.

What I have tried:

string = input()

name = string.split()
abr = ''
for i in name :
abr+=i[0]
output = (name[-1] + "" + abr[:len(abr)-1].upper())
print (output)
What is the mistake ? I am not getting gap between Tendulkar and S
Posted
Updated 19-Apr-22 2:35am

output = (name[-1] + "" + abr[:len(abr)-1].upper())

There isn't a space between the first and second double quote characters...
 
Share this answer
 
v2
Python
output = (name[-1] + "" + abr[:len(abr)-1].upper())

You need an actual space between the two double quote characters.
Python
output = (name[-1] + " " + abr[:len(abr)-1].upper())

But a better way would be to use one of the formatting features of Python, see 7. Input and Output — Python 3.9.12 documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900