1: Compare output A Output differs. See highlights below. Special character legend Input Your output Expected output 2: Compare output Lee 18 Lua 21 Mary Beth 19 Stu 33 -1 18, L. Lee 194 Lua 22 Mary 04 Stu 344
ive try this code and did the inputs and its not right . can someone help me ,,
fullName=str(input())
##List is for storing firstname,middlename,lastname separately,List is initially an empty list
List=[]
##Take an empty string word
word=""
##Start traversing fullName
for char in fullName:
##If any character is a space(' ') then,add the string stored in word variable in List
if(char==' '):
List.append(word)
##And again make word an empty string
word=""
##Otherwise,add current character with word
else:
word=word+char
##After completing this for loop,add the string stored in word variable in List
List.append(word)
##result will store the final result,it is initially an empty string
result=""
##If there are only firstname and lastname then,
if(len(List)==2):
##Add lastname then add ", " then add first character of firstname then add ".", with result
result=List[1]+", "+List[0][0]+"."
##If there are firstname,middlename and lastname then,
elif(len(List)==3):
##Add lastname then add ", " then add first character of firstname then add "." then add first character of middle name again add "." with result
result=List[2]+", "+List[0][0]+"."+List[1][0]+"."
##Now,display the result
print(result)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps