我现在正在学习python 3 . '''它要求用户输入两个字符串并找到字符串之间的汉明距离 . 输入序列应该只包括核苷酸'A','T','G'和'C' . 如果用户输入无效字符,程序应该要求用户重新输入序列 . 程序应该能够比较相同长度的字符串 . 如果字符串长度不同,程序应该要求用户再次输入字符串 . 用户应该可以输入上,下或两种情况作为输入'''
程序应按以下格式打印输出:
please enter string one: GATTACA
please enter string two: GACTATA
GATTACA
|| || |
GACTATA
The hamming distance of sequence GATTACA and GACTATA is 2
So the Hamming distance is 2.
我已在下面尝试过,但无法得到答案 .
def hamming_distance(string1, string2):
string1 = input("please enter first sequence")
string2 = input("please enter second sequence")
distance = 0
L = len(string1)
for i in range(L):
if string1[i] != string2[i]:
distance += 1
return distance
1 回答
行缩进错误:
L = len(strings1)