我必须从HP Codewars 2012返回拼写程序,我不知道我在做什么。这是我到目前为止所提供的帮助。我正在使用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))
答案 0 :(得分: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)