为什么两个字符串之间的断言失败了?

时间:2014-10-30 16:35:24

标签: python python-3.x assertion

我和Stepic一起上课。我认为这是两个失败的字符串之间的简单断言。我怎么能检查是否平等?谢谢,吉姆

def weights_to_letters(peptide):
    '''
    take a list of weights and convert to a string of aa letters
    '''
    from Bio.Data.IUPACData import protein_weights
    ret_string = ''
    for weight in peptide:
        for key in protein_weights.keys():
            if weight == round(protein_weights[key] - 18):   # -18 for weight of extra water molecule
                ret_string += str(key)
                break
    return ret_string
def test_weights_to_letters():
    print(type('WDG') , 'WDG', type(weights_to_letters([186,128,113])),     weights_to_letters([186,115,57]))
    assert weights_to_letters([186,128,113]) == 'WDG'

这就是出现的结果:

<class 'str'> WDG <class 'str'> WDG
Traceback (most recent call last):
  File "C:\Users\Jim\My Documents\GitHub\Stepic-Rosalind\BioAlgWeek2.py", line 238, in <module>
testcode()
  File "C:\Users\Jim\My Documents\GitHub\Stepic-Rosalind\BioAlgWeek2.py", line 228, in testcode
   test_weights_to_letters()
 File "C:\Users\Jim\My Documents\GitHub\Stepic-Rosalind\BioAlgWeek2.py", line 209, in    test_weights_to_letters
assert weights_to_letters([186,128,113]) == 'WDG'
AssertionError

1 个答案:

答案 0 :(得分:1)

您在test_weights_to_letters()的第一行中似乎有拼写错误。您正在将[186,115,57]传递给weights_to_letters,但您正在断言weights_to_letters([186,128,113])。