I have a 4x4 table to make from a list (not yet done) and I have to ask the user to input a number at a location (eg, b1,c2, column then row) but for the 2nd number (and onwards) the user has to put it adjacent to another number or else 'it is not allowed' will be displayed and it will prompt the user to input the location again. how do I do this with indexes?
I was thinking of doing
if above == ' ' and lower == ' ' and rightside == ' ' and leftside == ' ':
print('Number must be placed adjacent to another number!\nPlace Where?')
else:
continue
but I don't know how to write the indexes to check for the above, below, right and left >< I only know the basic things cuz I just started but here's my code
num_list = ['1','2','3','4','5',]
import random
num = random.choice(num_list)
table = [[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ']]
ss = {"W1":[0,0],
"W2":[1,0],
"W3":[2,0],
"W4":[3,0],
"X1":[0,1],
"X2":[1,1],
"X3":[2,1],
"X4":[3,1],
"Y1":[0,2],
"Y2":[1,2],
"Y3":[2,2],
"Y4":[3,2],
"Z1":[0,3],
"Z2":[1,3],
"Z3":[2,3],
"Z4":[3,3]}
ans = input('where would you like to place it: ')
index_ = ss[ans][0]
columns_ = ss[ans][1]
table[index_][columns_] = num
print(table)
Aucun commentaire:
Enregistrer un commentaire