1 Replies - 354 Views - Last Post: 26 January 2012 - 10:03 PM Rate Topic: -----

Topic Sponsor:

#1 Eddie_Nygma  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 09-January 12

Syntax advice!

Posted 26 January 2012 - 08:32 PM

All I need is a little guidance on how to correct my syntax error in idle3 on Fedora 16. The code has been taken from Python Programming for the Absolute Beginner:
# Geek Translator
# Demonstrates using dictionaries

geek = ["404": "clueless.   From the web error 404, meaning page not found.",
        "Googling": "searching the internet for background information on a person.",
        "Keyboard Plague" : "the collection of debris founf in computer keyboards.",
        "Link Rot" : "the process by which web pages become obsolete.",
        "Percussive Maintenance" : "the act of striking an electroic 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 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.")

# redefine 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":
    term = 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.") 

What do you guys think is the error here? I've found that syntax are the only real issues I've had with learning this stuff. If there is any sort of pdf I could practice with to improve my syntaxical skills, it would be much appreciated, anyone?

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax advice!

#2 sysop_fb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-January 12

Re: Syntax advice!

Posted 26 January 2012 - 10:03 PM

There's a lot of them, you're enclosing the dictionary in [)
The spacing is off and python requires spacing in code blocks be in a strict format.
So your elif blocks need to be tabbed over. You're missing parenthesis on some function calls and commas in some places. That's at first glance.

Is this code an exercise from your book for finding syntax errors?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1