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

Post Reply
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Python control statements [SOLVED]

Post by lotios611 »

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 :
        print(dictionary[word])
    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
Post Reply