大佬教程收集整理的这篇文章主要介绍了构建具有细节的 n x n 网格,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个家庭作业问题,只是把它放在那里。
我正在尝试构建一个 n x n 网格,其中第 r 行和第 c 列中的数字应该是 r * c 的最后一个数字(我也不完全明白这是在问什么,所以我'我也卡在那里)。 n 是用户提供的。
我的主要问题是我无法让网格按照我想要的方式工作。
这是我目前的代码:
# get dimension of the digit Box
reply = input( "Enter Integer: " )
n = int( reply )
# print an n-by-n grID one row at a time.
for r in range(0,n):
# handle prinTing of the row r entrIEs for the digit Box
print(r,end=" ")
print()
for c in range(0,n):
cell = (r * C) % 10
print(c,end=" ")
print()
这就是它返回的结果(在这次运行中 n = 4):
Enter Integer: 4
0
0 1 2 3
1
0 1 2 3
2
0 1 2 3
3
0 1 2 3
我不明白为什么这是它返回的内容,或者如何使它做我想要的。我知道如果我想获得它所要求的数字,我必须使用 %
运算符,但我不太知道如何使用它或在哪里使用它,所以我希望到目前为止我做得对。
提前致谢!
编辑:网格应该是这样的:
Enter Integer: 4
0 0 0 0
0 1 2 3
0 2 4 6
0 3 6 9
您正在打印 c 而不是单元格,并且还在打印 r。这是您的代码应该的样子:
# get dimension of the digit box
reply = input("Enter Integer: ")
n = int(reply)
# print an n-by-n grid one row at a time.
for r in range(0,n):
# handle prinTing of the row r entries for the digit box
# print(r,end=" ") REMOVE THIS
print()
for c in range(0,n):
cell = (r * C) % 10
# print(c,end=" ") REMOVE THIS
print(cell," ")
print()
@H_772_43@
以上是大佬教程为你收集整理的构建具有细节的 n x n 网格全部内容,希望文章能够帮你解决构建具有细节的 n x n 网格所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。