Answers for "short name in python"

1

initials of a name in python

raw_name = input("\nEnter Full Name : ") 
name = raw_name.strip()
bname  = name.split(' ')
lenofstr = len(bname)
fname = bname[0]
leofstrstr = str(lenofstr)
vlname = int(lenofstr) - 1
lname = bname[int(vlname)]
print("\nHi,"+bname[0])
print("\nHi,",end="")
for i in bname:
    if i == lname:
        break
    print(i[0].upper()+".",end="")
print(lname+"\n")

##This is the second method with more compact code
raw_name = input("\nEnter Full Name : ").strip().split(' ')
lname = raw_name[int(int(len(raw_name)) - 1)]
[print(i[0].upper()+".",end="") if i != lname else print(lname+"\n") for i in raw_name]
Posted by: Guest on November-23-2020
0

short name in python

name = input("Please enter a name: ") #Short the name (V.S. Mathur)
short = name.split()
n = [x[0] for x in short[:-1]]
print(*n, short[-1])
Posted by: Guest on December-21-2020
0

Fill in the gaps in the initials function so that it returns the initials of the words contained in the phrase received, in upper case.

def get_initials(fullname):
  xs = (fullname)
  name_list = xs.split()

  initials = ""

  for name in name_list:  # go through each name
    initials += name[0].upper()  # append the initial

  return initials
Posted by: Guest on May-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language