gpt4 book ai didi

python - 为什么这个打印功能在这里?

转载 作者:行者123 更新时间:2023-12-01 05:39:48 25 4
gpt4 key购买 nike

对于这可能是多么简单,我深表歉意,但我对这段代码的一部分感到有点困惑。

# 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() 函数除外

为什么会在那里?如果我删除它,就不会发生任何变化(据我所知),所以我很好奇它的意义。

最佳答案

不带参数的

print() 打印换行符。重点是在终端输出中显示一个空行。

关于python - 为什么这个打印功能在这里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17913894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com