首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个打印函数在这里?

为什么这个打印函数在这里?
EN

Stack Overflow用户
提问于 2013-07-28 23:09:31
回答 3查看 119关注 0票数 1

我为这可能太简单而道歉,但我对这段代码的一个部分感到有点困惑。

代码语言:javascript
复制
# Geek Translator
# Demonstrates using dictionaries

geek = {"404": "clueless.  From the web error message 404, meaning page not found.",
        "Googling": "searching the Internet for background information on a person.",
        "Keyboard Plague": "the collection of debris found in computer keyboards.",
        "Link Rot" : "the process by which web page links become obsolete.",
        "Percussive Maintainance" : "the act of striking an electronic device to make it work.",
        "Uninstalled" : "being fired.  Especially popular during the dot-bomb era."}

choice = None
while choice != "0":

    print(
    """
    Geek Translator

    0 - Quit
    1 - Look Up a Geek Term
    2 - Add a Geek Term
    3 - Redefine a Geek Term
    4 - Delete a Geek Term
    """
    )

    choice = input("Choice: ")
    print()

    # exit
    if choice == "0":
        print("Good-bye.")

    # get a definition    
    elif choice == "1":
        term = input("What term do you want me to translate?: ")
        if term in geek:
            definition = geek[term]
            print("\n", term, "means", definition)
        else:
            print("\nSorry, I don't know", term)

    # add a term-definition pair        
    elif choice == "2":
        term = input("What term do you want me to add?: ")
        if term not in geek:
            definition = input("\nWhat's the definition?: ")
            geek[term] = definition
            print("\n", term, "has been added.")
        else:
            print("\nThat term already exists!  Try redefining it.")

    # redefining an existing term
    elif choice == "3":
        term = input("What term do you want me to redefine?: ")
        if term in geek:
            definition = input("What's the new definition?: ")
            geek[term] = definition
            print("\n", term, "has been redefined.")
        else:
            print("\nThat term doesn't exist!  Try adding it.")

    # delete a term-definition pair
    elif choice == "4":
        input("What term do you want me to delete?")
        if term in geek:
            del geek[term]
            print("\nOkay, I deleted", term)
        else:
            print("\nI can't do that!", term, "doesn't exist in the dictionary.")

    # some unknown choice
    else:
        print("\nSorry, but", choice, "isn't a valid choice.")

input("\n\nPress the enter key to exit.")

除了choice = input(Choice: ")之后的print()函数,我理解所有这些是如何工作的

那是怎么回事?如果我删除它,什么都不会改变(据我所知),所以我对它的意义感到好奇。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-07-28 23:11:58

没有参数的print()打印换行符。重点是显示终端输出中的空行。

票数 2
EN

Stack Overflow用户

发布于 2013-07-28 23:12:09

它打印一个新行(在控制台输出中可以看到空行)。

票数 0
EN

Stack Overflow用户

发布于 2013-07-28 23:13:33

一个空的print()输出一个换行符,所以可能它存在的唯一原因是添加一个换行符?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17913894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档