PRODhruv_Kolte
PRODhruv_Kolte

Reputation: 5

How can len() function count the number of letters in a word entered by the user?

As the user inputs a different word the length of words will change so I am trying to store the .len() answer in a variable which is not working.

This is what I tried:

letter=input("TYPE A WORD--> ")
letter.upper()
NO=letter.len()
print (NO)

Though there is an error message saying:

Traceback (most recent call last):
File "main.py", line 3, in \<module\>
NO=letter.len()
AttributeError: 'str' object has no attribute 'len'

Upvotes: 0

Views: 523

Answers (3)

Ali Zahid Raja
Ali Zahid Raja

Reputation: 136

Updated code for you

letter=input("TYPE A WORD--> ") 
letter=letter.upper() 
NO=len(letter)
print (NO)

Upvotes: 1

Nour SIDAOUI
Nour SIDAOUI

Reputation: 342

give letter as argument to len()

NO = len(letter)

Upvotes: 1

Daniyal Ishfaq
Daniyal Ishfaq

Reputation: 247

There is no string.len() function in python. If you want to find the length of a string, you should use len(string) function. For example

NO = len(letter)

Upvotes: 2

Related Questions