如何编写一个程序,根据用户输入的 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/