从函数中打印出值

时间:2015-10-02 08:29:03

标签: python-2.7

好的,所以我的程序的问题是,由于某种原因,当我运行它时,底部的变量出现为"无"而不是人类DNA,小鼠DNA和未知DNA的原始字符串中的ATG数量的计数。我无法添加我定义这些DNA的部分因为它们的长度而且我很难添加它。我如何更改它,而不是输出在原始字符串中找到子字符串的次数作为函数外部的变量,并可以我在底部的格式输出它。

def countCodon(string, substring):
    i = string.find(substring)

def compareDNA(string1, string2):
    string1 = raw_input("Enter string 1: ")
    string2 = raw_input("Enter string 2: ")
    Hamming = 0
        for ch1, ch2 in zip(string1, string2):
                if ch1 != ch2:
                        Hamming += 1
    l = len(string1)
    similarity_score = ((l - Hamming)/(l))
    print similarity_score


HD = countCodon(humanDNA, "ATG")
MD = countCodon(mouseDNA, "ATG")
UD = countCodon(unknownDNA, "ATG") 
print "Mouse: ", HD
print "Human: ", MD
print "Unknown: ", UD

MU = compareDNA(mouseDNA, unknownDNA)
HU = compareDNA(humanDNA, unknownDNA)
if MU != HU and MU > HU:
    print "mouse"
elif MU != HU and MU < HU:
    print "human"
elif MU == HU:
    print "identity cannot be determined"

编辑:添加了第二个函数的混乱部分,遇到了类似的问题。

1 个答案:

答案 0 :(得分:0)

countCodon()没有返回值,因此HD = None

此外还有https://docs.python.org/2/library/string.html

  

string.find(s,sub [,start [,end]])

Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.

所以countCodon()给你的字符串&#34; ATG&#34;首先出现,而不是它出现的次数。