-5

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 *
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
SineCo
  • 33
  • 1
  • 2
  • 10
  • 4
    Your question is extremely unclear. What is "it"? Can you show some actual code? Perhaps the code without the `*`s? – Mad Physicist Apr 26 '18 at 19:26
  • `self.hidden = '*'` and then set hidden to ` ` when you guess and you display `self.val` when hidden isn't ` ` – depperm Apr 26 '18 at 19:26
  • This might help you : https://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python – Rohi Apr 26 '18 at 19:26

1 Answers1

-1

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 
Gillespie
  • 5,780
  • 3
  • 32
  • 54