我使用Python3在Visual Code Studio中进行编程。
所以我的第一个函数生成一个DNA String,我的第二个函数应该用两个不同的函数替换该字符串中的一对。我在这做错了什么。 (我得到的错误以错误的语法开头。)
再次感谢您的帮助。
import random as rd
def generateVirus(length):
a = [rd.choice(["AT", "GC","TA", "CG"])for i in range(length)]
return ("".join(a))
def mutate(virus):
virus = [v.replace(virus[int(rd.random()*(len(virus+1))), rd.choice([virus]for v in virus]
return virus
a = generateVirus(4)
b = virus(a)
答案 0 :(得分:1)
这看起来很平衡:
<a href="yourlink">your Hyper-text</a>
但是你永远不会定义你调用的def mutate(virus):
virus = [v.replace(virus[int(rd.random()*(len(virus+1)))]), rd.choice([virus]for v in virus)]
return virus
函数:
virus
答案 1 :(得分:0)
import random as rd
dna = ["AT", "GC","TA", "CG"]
def generateVirus(length):
a = [rd.choice(dna)for i in range(length)]
return ("".join(a))
def mutate(virus):
start = int(rd.random()*(len(virus)/2)) *2
replacement = rd.choice(["AT", "GC","TA", "CG"])
newvirus = virus[0:start] + replacement + virus[start+2:]
return newvirus
a = generateVirus(4)
b = mutate(a)
print(a)
print (b)
现在可以使用