Python simulates any input position of the form

Enter a value in the table at any position. I found a good way:

input输入
1. 行
2. 列

输入:1
excel每行输入文字

input输入位置
3.2
表示输入位置在:3行个列

I want to implement an input function similar to an Excel table, and I hope to be able to specify the input location. The code is as follows:

# 定义表格行数和列数,为了有趣,我们设定一个夸张的值
rows = 10  # 好大的表格啊,可以写下世界上所有的数据了!

cols = 9  # 字母表的全部字母都放进来,A到Z!

# 创建一个二维列表作为表格,这是我们的幕布,准备上演一场数据的盛宴!
table = [['' for j in range(cols)] for i in range(rows)]

# 获取用户输入的行号和列号,就像在找寻舞台的最佳位置
row_num = int(input('''请告诉我,你的输入在 请输入要输入的数据在第几行呢?
'''))
col_num = int(input('''请告诉我,你的输入在 请输入要输入的数据在第几列呢?
'''))

# 确认输入位置合法后,我们将为您端上一个精心准备的餐点
if row_num > 0 and row_num <= rows and col_num > 0 and col_num <= cols:
    data = input('请输入要输入的数据:')
    table[row_num-1][col_num-1] = data
else:
    print('非常抱歉,您选择的位置不在我们的舞台范围内。')

# 打印整个表格,让您欣赏到这场数据的精彩盛宴
print('------- 演出现场 -------')
for row in table:
    print(row)
print('-----------------------')

The notes incorporate elements of exaggeration and banter, describing the elements of the form and performance in a humorous way!

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_73675558/article/details/133535824