定义函数时出错

2024-09-30 06:27:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的任务是使o成为一个名为count\u nucleotides的函数,该函数用于处理字符串、一个单词和一个字母,并计算字母的出现数。例如:

计数核苷酸('ATCGGC','G')并给出2

计算核苷酸('ATCTA','G'),得出0

我的代码如下:

def count_nucleotides(dna, nucleotide):

count = 0
num = nucleotide

for char in dna:
    if char = num:
        count = count +1
return count

它返回一条消息:预期的是一个预期的块

我是python编程新手,所以如果有人能解释一下而不是问一些问题,比如在哪里定义这个或那个,我将不胜感激。这是我的第一个任务,所以请原谅我看到了什么


Tags: 函数字符串代码count字母单词numdna
1条回答
网友
1楼 · 发布于 2024-09-30 06:27:15

It returns a message: expected an intended block

你必须indent your function body

def count_nucleotides(dna, nucleotide):
    count = 0
    num = nucleotide

    for char in dna:
        if char == num:
            count = count + 1
   return count

相关问题 更多 >

    热门问题