对 python 很陌生,所以请原谅!
问题是...使输出看起来像
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
我使用用户输入的限制和副本数(在本例中为 5 和 3),所以我这样做了;
limit = int(input("Select upper limit"))
copies = int(input("Select number of copies"))
def output(limit):
for i in range(copies):
for x in range(limit):
print (x + 1, end=" ")
output(limit)
但是答案显示为 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5。我知道这是因为 end="" 但不知道如何解决它!任何帮助表示赞赏
请您参考如下方法:
为每个循环显式打印新行:
def output(copies, limit):
for i in range(copies):
for x in range(limit):
print (x + 1, end=" ")
print() # <----
# print() # Add this if you want an empty line
output(copies, limit)
