script output appears correct but still raises AssertionError

john polo jpolo at mail.usf.edu
Tue Jun 6 20:58:33 EDT 2017


Python People,

I am learning about assertions. I wrote a small script that takes 2 
inputs, an amino acid sequence and one residue symbol. The script should 
return what percent of the sequence is residue in output. The point of 
this script is to use assert for debugging. My script seems to work 
correctly, but when I use the assert statements that are supposed to 
test the script, the assertions indicate there is a problem with the 
script.


 >>> def aminosleft(sequence, res):
...     sequp = sequence.upper()
...     lens1 = len(sequp)
...     rep = res.upper()
...     reps2 = sequp.replace(rep,"")
...     lens2 = len(reps2)
...     resid = 100* (lens1 - lens2) / lens1
...     print(int(resid))
...
...
 >>> aminosleft("MSRSLLLRFLLFLLLLPPLP", "M")
5
 >>> assert aminosleft("MSRSLLLRFLLFLLLLPPLP", "M") == 5
5
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AssertionError

 >>> aminosleft("MSRSLLLRFLLFLLLLPPLP", "r")
10
 >>> assert aminosleft("MSRSLLLRFLLFLLLLPPLP", "r") == 10
10
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AssertionError

 >>> aminosleft("msrslllrfllfllllpplp", "L")
50
 >>> assert aminosleft("msrslllrfllfllllpplp", "L") == 50
50
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AssertionError

 >>> aminosleft("MSRSLLLRFLLFLLLLPPLP", "Y")
0
 >>> assert aminosleft("MSRSLLLRFLLFLLLLPPLP", "Y") == 0
0
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AssertionError

The script returns an integer. I don't know if the assertion uses an 
integer or if that matters. What is causing the AssertionError?


John



More information about the Python-list mailing list