def headName():
print (Name[0].upper())
def tailName():
print (Name[1:].lower())
Name = input("Please enter a name ")
headName()
tailName()
That's my code; I want to know how to concatinate headName() and tailName(), so that they're on the same line. Thanks
You can't do that without rewriting the functions. The newline is added by print
. Since you call print
inside the functions, nothing you do outside the function can undo the newline that was already added inside.
A better idea is to have your functions return the values, and then do the printing outside:
def headName():
return Name[0].upper()
def tailName():
return Name[1:].lower()
Name = input("Please enter a name ")
print(headName(), tailName(), sep="")
Incidentally, what you are doing can also be accomplished directly with Name.title()
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments