I am learning python with a book called "Python for Biologist". An exercise is to write a function that calculates the percentage of a residue in a protein sequence and evaluate it with the assert function, and this is my solution:
from _future_ import division def Residue_percentage(ProteinSequence, Residue): length = len(ProteinSequence) Residue = Residue.upper() residue_count = ProteinSequence.count(Residue) percentage = residue_count * 100 / length print(percentage) assert Residue_percentage("MSRSLLLRFLLFLLLLPPLP", "M") == 5
But I got an Assertion error. If I include
return percentage the assertion pass the test.
'Do you know what is happening here?
Thank you so much!