Python control statements [SOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Python control statements [SOLVED]

Postby lotios611 on Sun Nov 29, 2009 1:44 pm

I'm trying to make a dictionary. When I run this code, I get prompted to enter my option. If I enter b, it runs the code for c.

Code: Select all
dictionary={"Hello" : "A word", "Hi" : "Another word", "Yo!" : "Yet another word"}
print("Welcome to the dictionary.\n")
print("To begin, type your option.")
print("a) Search for a word")
print("b) Enter a word")
print("c) Display all words")
answer = raw_input()

if answer == "a" or "a)" or "A" or "A)" :
    word = raw_input("What word would you like to search for? ")
    if word in dictionary :
    else :
        print("Word not found!")

elif answer == "b" or "b)" or "B" or "B)" :
    word = raw_input("Enter a word: ")
    definition = raw_input("Enter the definition: ")
    dictionary[word] = definition
elif answer == "c" or "c)" or "C" or "C)" :
    for k, v in dictionary.iteritems() :
        print (k+" - "+v)

EDIT: I figured it out. I had "if answer == "b" or "b)" It should of been "if answer == "b" or answer == "b)".
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Chaos Rift Regular
Chaos Rift Regular
Posts: 162
Joined: Sun Jun 14, 2009 1:05 pm

Return to Programming Discussion

Who is online

Users browsing this forum: No registered users and 1 guest