Reputation: 5
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
Reputation: 136
Updated code for you
letter=input("TYPE A WORD--> ")
letter=letter.upper()
NO=len(letter)
print (NO)
Upvotes: 1
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