python - 如何使用IDLE在Python中的列和行中形成数字线

标签 python

如何编写一个程序,根据用户输入的 python 来创建数字网格。 用户将输入起始整数、行数和列数。

我做到了

i = eval(input("Enter the starting integer:"))
r = eval(input("Enter the number of rows:"))
c = eval(input("Enter the number of columns:"))
for x in range (i):
    print(*range(i))

问题是它不是以我输入的数字开头, 我该如何解决这个问题?

输出应该是这样的: 例如,

如果我输入整数:6,行:3,列:4 其结果应该是:

6 7 8
9 10 11
12 13 14
15 16 17

最佳答案

此代码产生所需的输出:

i = eval(input("Enter the starting integer:"))
r = eval(input("Enter the number of rows:"))
c = eval(input("Enter the number of columns:"))

for y in range(c):
    for x in range(r):
        print(i,' ', end='')
        i += 1
    print()

Enter the starting integer:6
Enter the number of rows:3
Enter the number of columns:4
6  7  8  
9  10  11  
12  13  14  
15  16  17  

注意表格有 4 行 3 列。

关于python - 如何使用IDLE在Python中的列和行中形成数字线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103805/

相关文章:

python - 比较两个字典的键并使用与另一个字典中的键不匹配的键、值对创建一个字典 - Python

python - 如何使用 python boto3 获取 s3 中文件的最后修改时间?

python - 相当于 python __getattr__/__setattr__ 的 scala

python - "' 模块 ' object has no attribute ' SSLContext '"使用 flocker-api 时出错

python - 观察计数与预期计数之间的差异表

python - 如何锁定 python (.py) 文件进行编辑?

python - 第二次尝试读取打开的文件时没有数据

javascript - 单击 Plotly 散点图中的数据点时打开 URL [Python]

python - Python 中的列表(使用 NLTK)

python - 将 2D 和 1D 数组相乘以获得 3D 数组