The dictionary currently has a few definitions in it, but it keeps only returning the definition for "noob". Anything that's entered returns that index. Why? Here's the code:

#1337 to Human dictionary:
leet={"1337":"l-EET/nReally Awesome","noob":"(n00b) nOOb/nPerson who can't accept that s/he's wrong",
      "-xxors":"Suffix, pron: zors.\nUsed to accent an important verb, e.g. roxxors",
      "newb":"new-b,\nPerson who is new to a game and needs help. Not to be\nconfused with noob"}
word=1
while word != "" or "0":
    word = raw_input("Input a word to define: ")
    if word == "noob" or "n00b" or "nOOb":
        print leet['noob']
    elif word == "leet" or "elite" or "1337" or "l33t":
        print leet['1337']
    elif word == "xxors" or "roxxors" or "boxxors" or "-xxors":
        print leet['-xxors']
    elif word == "newb" or "newbie":
        print leet['newb']

Even when word=0 or "". What's going on?

Recommended Answers

All 3 Replies

Your or statements weren't written correctly. In this case it's simpler to see if the word is in a tuple (or list) of choices:

#1337 to Human dictionary:
    
leet = {
"1337": "l-EET/nReally Awesome",
"noob": "(n00b) nOOb/nPerson who can't accept that s/he's wrong",
"-xxors": "Suffix, pron: zors.\nUsed to accent an important verb, e.g. roxxors",
"newb": "new-b,\nPerson who is new to a game and needs help. Not to be\nconfused with noob"
}
    
word = 1
while word not in ("", "0"):
    word = raw_input("Input a word to define: ")
    # correct use of or ...
    if word == "noob" or word == "n00b" or word == "nOOb":
        print leet['noob']
    # simpler, is word in a tuple (or list) ...
    elif word in ("leet", "elite", "1337", "l33t"):
        print leet['1337']
    elif word in ("xxors", "roxxors", "boxxors", "-xxors"):
        print leet['-xxors']
    elif word in ("newb", "newbie"):
        print leet['newb']

Fixed it! Here's the new code:

#1337 to Human dictionary:
leet={"1337":"l-EET/nReally Awesome","noob":"(n00b) nOOb\nPerson who can't accept that s/he's wrong",
      "-xxors":"Suffix, pron: zors.\nUsed to accent an important verb, e.g. roxxors",
      "newb":"new-b,\nPerson who is new to a game and needs help. Not to be\nconfused with noob"}
word=1
while word not in ("","0"):
    word = raw_input("Input a word to define: ")
    if word in ("noob","n00b","nOOb"):
        print leet['noob']
    elif word in ("leet","elite","1337","l33t"):
        print leet['1337']
    elif word in ("xxors","roxxors","boxxors","-xxors"):
        print leet['-xxors']
    elif word in ("newb","newbie"):
        print leet['newb']
print "Thankyou for using the dictionary"
stop = raw_input("Press any key to quit")

I'm quite proud of it!

Fixed it! Here's the new code:

#1337 to Human dictionary:
leet={"1337":"l-EET/nReally Awesome","noob":"(n00b) nOOb\nPerson who can't accept that s/he's wrong",
      "-xxors":"Suffix, pron: zors.\nUsed to accent an important verb, e.g. roxxors",
      "newb":"new-b,\nPerson who is new to a game and needs help. Not to be\nconfused with noob"}
word=1
while word not in ("","0"):
    word = raw_input("Input a word to define: ")
    if word in ("noob","n00b","nOOb"):
        print leet['noob']
    elif word in ("leet","elite","1337","l33t"):
        print leet['1337']
    elif word in ("xxors","roxxors","boxxors","-xxors"):
        print leet['-xxors']
    elif word in ("newb","newbie"):
        print leet['newb']
print "Thankyou for using the dictionary"
stop = raw_input("Press any key to quit")

I'm quite proud of it!

long time ago, i did a leet of my own, just for fun..no fine tuning/optimization or whatsoever..

import random
n = "|\\|" ; w = "\\/\\/" ; h = "|-|" ; u = "|_|"; R = "|2" ; D = "|)" 
F = "|=" ; J = "_/" ; K = "|<" ; M = "|\/|"; p = "|o" ; d = "o|" 
V = "\/" ; x = "><"

lookup = [  ['a', ['4'] ], ['A', ['4',] ],
            ['b', ['b','8'] ], ['B', ['B','8'] ],
            ['c', ['c','(','<'] ], ['C', ['C','(','<'] ],
            ['d', ['d',d] ], ['D', ['D',D] ],
            ['e', ['3'] ], ['E', ['3',] ],
            ['f', ['f'] ], ['F', ['F',F] ],
            ['g', ['9','g'] ], ['G', ['6'] ],
            ['h', [h,'h'] ], ['H', ['H',h] ],
            ['i', ['!','1'] ], ['I', ['!','1',] ],
            ['j', ['j',J] ], ['J', ['J',J] ],
            ['k', ['k',K] ], ['K', ['K',K] ],
            ['l', ['1','|'] ], ['L', ['1'] ],
            ['m', ['m',M] ], ['M', ['M',M] ],
            ['n', ['n',n] ], ['N', ['N',n ,]   ],
            ['o', ['0'] ], ['O', ['0'] ],
            ['p', ['p',p] ], ['P', ['P'] ],
            ['q', ['q'] ], ['Q', ['Q'] ],
            ['r', ['r'] ], ['R', ['R',R ]],
            ['s', ['$','5'] ], ['S', ['$','5'] ],
            ['t', ['7','t'] ], ['T', ['7','T'] ],
            ['u', ['u',u] ], ['U', [u] ],
            ['v', ['v',V] ], ['V', ['V',V] ],
            ['w', ['w',w,] ], ['W', ['W',w,] ],
            ['x', ['x',x] ], ['X', ['X',x] ],
            ['y', ['y','j'] ], ['Y', ['Y','j'] ],
            ['z', ['z','2'] ], ['Z', ['Z','2'] ],
          ]

if __name__ == '__main__':
    english = ['about']
    all = dict(lookup)
    for e in english:
        print "\n%s = " %(e) ,
        for char in e:
            for key, val in all.iteritems():
                if key == char:
                    random.shuffle(val)
                    v = val[0]
                    print "%s" % (v),
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.