2014-10-30 46 views
0

我正在和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 
+2

你打印的這個值:'weights_to_letters([186,115,57])',但在比較,你使用這個:'weights_to_letters([186128113])'。 – dano 2014-10-30 16:38:30

回答

1

你似乎有一個錯字在test_weights_to_letters的第一行()。你將[186,115,57]傳遞給weights_to_letters,但是你斷言weights_to_letters([186,128,113])。

+0

這是令人尷尬:) – 2014-10-30 22:17:26

+0

@JimSmith但容易固定,這是這麼多漂亮! – furkle 2014-10-30 22:17:54