mccdlibby
mccdlibby

Reputation: 181

Why is this print function here?

I apologize for how simplistic this may be, but I am a little confused looking at one part of this code.

# 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.")

I understand how all of this works with the exception of the print() function after choice = input(Choice: ")

Why is that there? If I remove it, nothing changes (as far as I can tell), so I was curious about its significance.

Upvotes: 1

Views: 135

Answers (3)

Kay
Kay

Reputation: 798

An empty print() outputs a newline, so maybe the only reason it's there is to add a newline?

Upvotes: 0

Femaref
Femaref

Reputation: 61467

It prints a new line (which is visible as an empty line in the console output).

Upvotes: 0

Marcin
Marcin

Reputation: 49856

print() with no parameters prints a newline. The point is to show a blank line in the terminal output.

Upvotes: 2

Related Questions