1) у вас ошибка - ваш return
имеет отступ на одну дополнительную вкладку вправо
2) используйте dict
:
def base_counter(DNA):
dna_dict = {
"A": 0,
"T": 0,
"G": 0,
"C": 0,
}
for base in DNA:
if base == "A":
dna_dict["A"] += 1
elif base == "T":
dna_dict["T"] += 1
elif base == "G":
dna_dict["G"] += 1
elif base == "C":
dna_dict["C"] += 1
return dna_dict
dna = "AAGCTACGTGGGTGACTTT"
counts = base_counter(dna)
for base, count in counts.items():
print(base, count)
, но если вам нужносохранить функцию как есть:
def base_counter(DNA):
A = 0
T = 0
G = 0
C = 0
for base in DNA:
if base == "A":
A = A + 1
elif base == "T":
T = T + 1
elif base == "G":
G = G + 1
elif base == "C":
C = C + 1
return A,T,G,C
dna = "AAGCTACGTGGGTGACTTT"
counts = base_counter(dna)
for base, count in zip("ATGC", counts):
print(base, count)