0

This is my code:

length = len(input("What is your name?\n"))
print("The length of your name is ",length,".")

Now, this is my output:

What is your name?
Shary
The length of your name is  5 .

I would like my output to be like this "The length of your name is 5." As you can imagine, by placing a comma next to the Integer length, I have an extra space I would like to take care of. I am new to Python so I do not really know how to solve this.

Any help would be greatly appreciated.

Mantra.
  • 1
  • 2

1 Answers1

1

By default, print puts spaces between each of the arguments it receives.

There are a number of ways you can get the behavior you want. Here are a few different options:

# The 'sep' argument changes what separator is used between args:
print("The length of your name is ", length, ".", sep='')

# String concatenation doesn't implicitly add any separators:
print("The length of your name is " + str(length) + ".")

# String formatting similarly lets you be more precise with your spacing:
print("The length of your name is {}.".format(length))
print(f"The length of your name is {length}.")
0x5453
  • 12,753
  • 1
  • 32
  • 61