我需要打印出一个4x4的表,标记(a B C D)水平和垂直1234,并要求用户在表中放置一个随机生成的数字(例如:A1, B2)
num = randomly generated number
table = [ [' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ']]
ans = input('where would you like to place it?')
我用字典赋值A1: table[0][0]等等尝试用:
替换该值if ans in dictionary:
table.replace(dictionary.get(ans),num)
它不适合我,但我只知道如何这样做。
num = 'randomly generated number'
table = [[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ']]
ss = {'B1': [0,1]}
ans = input('where would you like to place it: ')
index_ = ss[ans][0]
columns_ = ss[ans][1]
table[index_][columns_] = num
print(table)
你认为它能满足你的要求吗?