【问题标题】:Need to make rows and columns需要制作行和列
【发布时间】:2023-02-06 02:17:35
【问题描述】:

nRow=int(input("行数:"))
nCol=int(input("列数:"))
ch=input("哪些字符?") 我=1 j=1 当 j<=nCol 时: 当我<=n行时: 打印(通道,结束='') 我=我+1 打印(通道,结束='') j=j+1`

这里我尽量在while循环中做一列和一行,但是就是不行。当我输入行号和列号时,它们只会生成一行。就像(行:2 列:3 个字符:a)一样,我希望得到一个具有 2 行和 3 列的表格,但我只是 - aaaaa。

【问题讨论】:

    标签: python loops while-loop row


    【解决方案1】:

    您只需要更改循环,以便在每一行之后转到新行。你也可以像这样使用for in range

    for row in range(nRow):
        for col in range(nCol):
            print(ch, end=' ')
        print()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 2020-06-10
      相关资源
      最近更新 更多