How to hide a value in Python? (display it as a *)

Question:

I am making a simple game in python and I want to display all the numbers in the beginning as stars like this:

* * *
* * *
* * *

Then after you choose a position (for example 2,3) it will show you what number in that position.

So in my class I want to initialize these points:

def __init__(self, val):
    self.val = val
    # I want to set the created number to be displayed as *
Asked By: SineCo

||

Answers:

This should be enough code to get you started. You just need a flag to determine whether a number should be hidden or not:

grid = [
  [{"number": 1, "hidden": True}, {"number": 5, "hidden": False}, {"number": 8, "hidden": True}],
  [{"number": 3, "hidden": True}, {"number": 2, "hidden": True}, {"number": 4, "hidden": False}],
  [{"number": 9, "hidden": True}, {"number": 7, "hidden": False}, {"number": 3, "hidden": False}]
]

for row in grid:
  for column in row:
      print("*" if column["hidden"] else column["number"], "", end="")
  print()

Prints:

* 5 * 
* * 4 
* 7 3 
Answered By: Gillespie
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.