-2

since this next simple code worked for me:

print(len(input("¿whats your name? i will give you how many letters it has if you tell me: ")))

I tried to make it fancier by trying to code a more "complete" answer:

print("your name has " + len(input("whats your name? i will give tell you how many letters it has if you tell me: ")) + " in it")

but it doesnt seem to work out.

the "output" tell me this:

Traceback (most recent call last): File "main.py", line 7, in print("your name has " + len(input("whats your name? i will give tell you how many letters it has if you tell me: ")) + " in it") TypeError: can only concatenate str (not "int") to str 

bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • For future reference, try searching your error on google before posting a question. While you are first learning to code, 99% of the questions and errors you will have, have already been answered on this site. As far as the error, you are getting this error because you are adding a string and an integer which aren't compatible for this kind of operation. – unltd_J Apr 20 '21 at 00:41

2 Answers2

1

You can not concatenate an integer (which is what len returns) with the strings before and after it, but you can put it between curly brackets in a f' string like this:

print(f'your name has {len(input("What is your name? I will give tell you how many letters it has if you tell me: "))} letters in it.')
pakpe
  • 5,391
  • 2
  • 8
  • 23
0

len() returns integer and you need a string to concatenate.

try converting len to string using str() like this:

print("your name has " + str(len(input("whats your name? i will give tell you how many letters it has if you tell me: "))) + " in it")