我正在和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
你打印的這個值:'weights_to_letters([186,115,57])',但在比較,你使用這個:'weights_to_letters([186128113])'。 – dano 2014-10-30 16:38:30