python - Building upon existing function -


i playing around functions in order further understanding of them , curious, @ possible return users first name , last initial using following function without adding additional functions?

name = raw_input("please enter full name: ")  def username(a):     print(a[0:6]+a[-1]) username(name) 

if length of input names can vary , number of names have use function split , index. if user can enter single name need add if or try...except.

a[:a.index(' ')]) first name, beginning of input first space

index returns valueerror if character isn't found if might enter first name surround try...except

a.split()[-1][0] first letter of last name if enter more 2 names (billy bob joe -> billy j)

name = raw_input("please enter full name: ")  def username(a):     print(a[:a.index(' ')]+' '+a.split()[-1][0]) username(name) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -