|
本帖最后由 MollyABC 于 2017-1-25 18:01 编辑
def count_nucleotides(dna, nucleotide):
""" (str, str) -> int
Return the number of occurrences of nucleotide in the DNA sequence dna.
>>> count_nucleotides('ATCGGC', 'G')
2
>>> count_nucleotides('ATCTA', 'G')
0
"""
这里是要数str2在str1中出现的次数
新手刚入门,遇到不会写的题目了,请问这里该如何return ? 好沮丧,求帮忙!
我自己写的是这样子的:
num_nucleotides=0
for nucleotide in dna:
if nucleotide in dna:
num_nucleotides=num_nucleotides+1
return num_nucleotides
但是结果是错的,我也不知道问题在哪里
|
|