归还你需要的咒语

2024-10-03 13:17:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须从HP Codewars 2012中返回spellbinder程序,我不知道我在做什么。这是我到目前为止所拥有的,请帮忙。我使用的是python3.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))

Tags: thetoorg程序httpstring链接www
1条回答
网友
1楼 · 发布于 2024-10-03 13:17:42

我不想这么做。你知道吗

你应该试着去调试和解决问题。你知道吗

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)

相关问题 更多 >