Here again with a proposal and a need;
as you can know from my previuos question i'm building a simple slot machine script.
I want five numbers to be printed in a minimal board, the board is 9x9 '[]'
like this:
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
numbers will be printed in center of the grid like this:
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] O O O O O [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
[] [] [] [] [] [] [] [] []
but what i want, like everyone building a board like this one,array is a fixed width string with numbers inside it.
the function that print out the entire board is this one:
slot = []
for row in range(9):
slot.append(['[]'] * 9)
def print_slot(slot):
for element in slot:
print(" ".join(element))
print_slot(slot)
how can i use a format tool like .format
if in the second part of my script i will need to acces the list slot
at the exact index of every '[]'
to do a substitution with numbers?
def game_start():
if start == str(' '):
first_n = random.randint(0, 9)
second_n = random.randint(0, 9)
third_n = random.randint(0, 9)
fourth_n = random.randint(0, 9)
fifth_n = random.randint(0, 9)
slot[4][2] = str(first_n)
slot[4][3] = str(second_n)
slot[4][4] = str(third_n)
slot[4][5] = str(fourth_n)
slot[4][6] = str(fifth_n)
print_slot(slot)
game_start()
it's time to build the array for the ultimate fixed width board for everyone in need of it!
:-)