-2

list:

board = []
for i in range(0,5):
  board_list = ["o"] * 5
  board.append(board_list)
print str(board).upper()

Problem here how can I make it so that I can lower or upper this in Python 3.x? If I were to do the normal way without using a list or a dictionary it would be :

board = ("adsfdsfsd")
print board.upper()

So I want to know how I need to proceed in order to be able to solve this, and have the letters be showing the letter o uppercase like this:

[['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O']]

instead of it lowercased like this:

[['o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o']]

@Kevin: so the error that appears is the following:

Traceback (most recent call last):
File "<stdin>", line 5, in <module>
TypeError: 'dict' object is not callable

@Kevin: ideone to debug: http://ideone.com/VFUWfs

I'm using this site between to test code: http://labs.codecademy.com/#:workspace since I'm doing the course over there

likewyise
  • 101
  • 2
  • Is this your actual code? `{'gold' : 500]} * 5` is not valid Python. – Kevin Sep 08 '14 at 14:27
  • 1
    That code won't work because you haven't indented it correctly, have a random `]` and can't `append` to or multiply a dictionary. In general, though, to do the same thing to every item in a collection, use a `for` loop or `map`. – jonrsharpe Sep 08 '14 at 14:28

1 Answers1

1

If your question is "when printing non-strings, how do I make them appear in all uppercase?", then the answer is "convert the non-string into a string, then use upper."

>>> d = {"Gold": 500}
>>> print str(d).upper()
{'GOLD': 500}
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • Hello I just updated my question: so that it appears correctly indented, and also it goes straight to the point of it, still I can't put my list into uppercases the letter o, not working – likewyise Sep 08 '14 at 14:46
  • So `print str(board).upper()` isn't working? It works on my machine. What error are you getting? – Kevin Sep 08 '14 at 14:59
  • After inputting: board = [] for i in range(0,5): board_list = ["o"] * 5 board.append(board_list) print str(board).upper() if shows me Traceback (most recent call last): File "", line 5, in TypeError: 'dict' object is not callable – likewyise Sep 08 '14 at 15:01
  • 1
    I suspect you have overwritten the built-in function `str` by doing something like `str = {}` earlier in your code. – Kevin Sep 08 '14 at 15:05
  • I'm going to input on my edit of the title what I am inputting – likewyise Sep 08 '14 at 15:10
  • [Here](http://ideone.com/E4DcUT) is a link to an online interpreter demonstrating that the code should work. If you can post a similar Ideone link to code that gives a `TypeError`, I would be happy to debug it :-) – Kevin Sep 08 '14 at 15:14
  • ideone to debug: http://ideone.com/VFUWfs I'm using this site between to test code: http://labs.codecademy.com/#:workspace since I'm doing the course over there – likewyise Sep 08 '14 at 15:29
  • That Ideone is giving a SyntaxError because you specified Python 3 as the language, but Python 3 doesn't allow print statements without parentheses. [Here](http://ideone.com/cWbcVG) is a version that uses parentheses and works as expected. Still no `TypeError` to be seen. – Kevin Sep 08 '14 at 15:31
  • Note that the Codecademy editor remembers the result of code you previously ran, as long as you don't refresh the page. It's possible that you wrote `str = {}`, ran it, deleted that line, and wrote your current code. `str` will still have the bad value, even though the code is gone. – Kevin Sep 08 '14 at 15:34
  • well thanks it has been solved, I didn't know about that – likewyise Sep 08 '14 at 15:39