Oct-01-2017, 07:37 PM
Hello everyone. I try to make o function which takes 2 strings, a word and a letter, and counts how many times there is the letter in the word. Here is the code:
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
"""
count = 0
for char in dna:
if nucleodite in dna:
count = count +1
return count
print(count)
and here is the error message:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
count_nucleotides('ATCGGC', 'G')
File "C:\Users\Giannis\Desktop\Python Assegments\Week 4\week4.py", line 51, in count_nucleotides
if nucleodite in dna:
NameError: name 'nucleodite' is not defined
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
"""
count = 0
for char in dna:
if nucleodite in dna:
count = count +1
return count
print(count)
and here is the error message:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
count_nucleotides('ATCGGC', 'G')
File "C:\Users\Giannis\Desktop\Python Assegments\Week 4\week4.py", line 51, in count_nucleotides
if nucleodite in dna:
NameError: name 'nucleodite' is not defined