![]() |
TypeError: string indices must be integers - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: string indices must be integers (/thread-38073.html) Pages:
1
2
|
RE: TypeError: string indices must be integers - deanhystad - Aug-31-2022 And title() is a better choice than upper() or lower() RE: TypeError: string indices must be integers - rob101 - Aug-31-2022 Keep in mind that if you do use .title() , then "Paris" in not the same as "PARIS" or "paris" , which is why I prefer to store data in one format or another (usually lowercase) and then case change any user input: user_input = input("Enter your text: ").lower() so that it's easy to make any comparison to the stored data: if user_input == data: Any output can be formatted correctly, as in, for example: print(f"{city}".title()) where city could be "PARIS" or "paris" , or whatever.
RE: TypeError: string indices must be integers - deanhystad - Aug-31-2022 You can change both the answer and the reply to anything as long as it is the same. I was thinking that title() would work well. If the quiz answers are in title case (Paris, Berlin) they look nice when you do this: print(f"Incorrect :(\nThe correct answer is: {a}")You could also do this: if input("Answer? ").upper() == a.upper():then the quiz answers can use any capitalization you want. quiz = ( ("What is the capital of France?", "Paris"), ("What is the point where two lines meet?", "vertex") ) |