-2

我必须从 HP Codewars 2012 返回 spellbinder 程序,我不知道自己在做什么。这是我到目前为止所拥有的,请帮忙。我正在使用 python 3.3.0。这是链接http://www.hpcodewars.org/past/cw15/problems/2012ProblemsFinalForPrinting.pdf

def  fix (string):
'''The function of the repaired by a
speelbot abused Dictionary

word -> word to be repaired
a -> the point-to-exchange
b -> the correct letter

'''
    word, a, b =  string.split ( " " )

    return  word.replace (a, b)


for  word in  [ '"MUSTARD MC " , "JUNK J TR" , "MONSTER ON A" ']:
    print (word, "->" to repair (word))
4

1 回答 1

0

不想这样做。

您应该考虑尝试调试和解决问题。

def fix(item):
    '''The function of the repaired by a
    speelbot abused Dictionary

    word -> word to be repaired
    a -> the point-to-exchange
    b -> the correct letter

    '''
    try:
        word, a, b = item.split(" ")
    except ValueError:
        print "Invalid Input"

    return word.replace(a, b)

if __name__ == "__main__":
    for w in ["MUSTARD M C", "JUNK J TR", "MONSTER ON A"]:
        print w, "-> ", fix(w)
于 2013-02-07T05:24:58.127 回答