[英]Printing times tables: How do I add a new line between results?
Simple one here I am sure but I am still learning and I am not too sure on how I can add lines in between the lines of the timetable. 我敢肯定,这里很简单,但是我仍在学习,而且我不太确定如何在时间表的行之间添加行。
This is my code: 这是我的代码:
def table_all():
for line in range(1,13):
for table in range(1,13):
print(line * table, end=" ")
print
This is what I want it to look like: 这是我想要的样子:
If anybody has a more efficient way of doing this then please share. 如果有人有更有效的方法,请分享。 Don't hate me for asking a simple question, everybody has to start learning somewhere. 不要恨我问一个简单的问题,每个人都必须在某个地方开始学习。
Print a new line
at the end of every iteration of outer loop. 在外循环的每次迭代结束时打印new line
。
def table_all():
for line in range(1,13):
for table in range(1,13):
print(line * table, end=" ")
print("\n")
This will return a string thats contain a new line each linefor: 这将返回一个包含以下内容的字符串:
def table_all():
string = ""
for line in range(1,13):
for table in range(1,13):
string += str(line * table) + " "
string += "\n"
return string
print(table_all())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.