简体   繁体   English

打印时间表:如何在结果之间添加新行?

[英]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

here is the result: 结果如下: Outout

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.

相关问题 我如何让这个 for 循环每 8 次开始一个新行 - how do I make this for loop start a new line every 8 times 如何在不打印到新行的情况下将输出更新到命令行? - How do I update output to the command line without printing to a new line? 如何将计算结果添加到数据框中的新列? - How do I add the results from a calculation to a new column in a dataframe? Python Selenium:如何在正确的 position 处添加新行? - Python Selenium: How do I add a new line at the correct position? 如何在合并文件之间添加一个空行 - How do I add a blank line between merged files 循环保持打印出相同的结果? (python 3.x)如何在每行上打印具有不同结果的循环? - loop keeps printing out same result? (python 3.x) How do I print a loop with different results on each line? Python:如何在打印时换行? - Python: How can I make a new line when printing? 在python中使用.writelines时,如何使代码在文档的新行上添加新输入? - How do I make my code add new inputs on a new line in a document while using the .writelines in python? 我如何将语言工具应用于 Python df 并将结果添加为 df 中的新列? - how do i apply language tool to Python df and add results as new column in df? 动态打印时,如何删除整行? - When printing dynamically, how do I remove the entire line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM