Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'str' object has no attribute 'toLowerCase'

Tags:

python

I am writing a program that asks you to enter 5 words (one at a time) and then prints them out in reverse order. (I am using Python 3.3.2) Here is what it should look like: http://s11.postimg.org/rayd8m3oj/Untitled.png

But instead it gives me this:

http://s10.postimg.org/c1p590vex/example.png

Here is my code:

fifth_word = input("Please enter your 1st word: ")
fifth_word = fifth_word.toLowerCase
fourth_word = input("Please enter your 2nd word: ")
fourth_word = fourth_word.toLowerCase
third_word = input("Please enter your 3rd word: ")
third_word = third_word.toLowerCase
second_word = input("Please enter your 4th word: ")
second_word = second_word.toLowerCase()
first_word = input("Please enter your 5th word: ")
first_word = first_word.capitalize()
print("The sentence is: " + first_word + second_word + third_word + fourth_word + fifth_word)

Thanks in advance

like image 583
ComputerXplorer Avatar asked Sep 17 '13 16:09

ComputerXplorer


1 Answers

The Python str class does not contain a method named toLowerCase. The method that you are looking for is lower.

When you are faced with such an error message, the first thing you should do is to see what the class in question can do.

>>> s = 'some string'
>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__'
, '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul_
_', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__'
, '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_m
ap', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'ist
itle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition
', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

As you can see, toLowerCase is not here. But you can also see lower which should steer you in the right direction. And don't be afraid to look in the documentation which is invariably of excellent quality.

like image 99
David Heffernan Avatar answered Oct 31 '22 22:10

David Heffernan