试图通过让用户输入列数和行数来打印文本,我哪里出错了?

2024-06-27 02:23:49 发布

您现在位置:Python中文网/ 问答频道 /正文

print ("number of rows")
rows = int(input())
print ("number of columns")
col = int(input())
for noofrows in range(0,rows,1):
    print(":)")
    for noofcol in range(0,col,1):
        print(":)",end="")
:)
:):):):)
:):):):)
:):):)
this is the output i get

当我做3乘3的时候,它会给我一张由1、4、4、3张笑脸组成的列表


Tags: columnsofinnumberforinputrangecol
1条回答
网友
1楼 · 发布于 2024-06-27 02:23:49

有些print是不正确的

for noofrows in range(rows): #same as range(0,row,1)
    #don't print a smiley here
    #print(":)")
    for noofcol in range(col): #same as range(0,col,1)
        print(":)",end="")
    #print an empty string instead and at the end of the loop
    print("")

Python 2中的等效代码将row作为3,将col作为3个输出

:) :) :)
:) :) :)
:) :) :)

相关问题 更多 >