我有这两个功能:
def MatchRNA(RNA, start1, end1, start2, end2):
Subsequence1 = RNA[start1:end1+1]
if start1 > end1:
Subsequence1 = RNA[start1:end1-1:-1]
Subsequence2 = RNA[start2:end2+1]
if start2 > end2:
Subsequence2 = RNA[start2:end2-1:-1]
return Subsequence1, Subsequence2
def main():
RNA_1_list = ['A','U','G','U','G','G','G','U','C','C','A','C','G','A','C','U','C','G','U','C','G','U','C','U','A','C','U','A','G','A']
RNA_2_list = ['C','U','G','A','C','G','A','C','U','A','U','A','A','G','G','G','U','C','A','A','G','C']
RNA_Values = {'A': 1, 'U': 2, 'C': 3, 'G': 4}
RNA1 = []
RNA2 = []
for i in RNA_1_list:
if i in RNA_Values:
RNA1.append(RNA_Values[i])
for i in RNA_2_list:
if i in RNA_Values:
RNA2.append(RNA_Values[i])
RNA = list(input("Which strand of RNA (RNA1 or RNA2) are you sequencing? "))
Start1, End1, Start2, End2 = eval(input("What are the start and end values (Start1, End1, Start2, End2) for the subsequences of the strand? "))
Sub1, Sub2 = MatchRNA(RNA, Start1, End1, Start2, End2)
print(Sub1)
print(Sub2)
因此,当我运行 main 函数并给出输入(例如):RNA1,然后是 3、14、17、28 时,它应该打印两个列表,[2,4,4,4,2,3,3,1,3,4,1,3]
并且[4,2,3,4,2,3,2,1,3,2,1,4]
. 我在测试这段代码时无意中使用了 Python 2.7,它运行良好(没有那个 eval),但是当我在 3.3 中运行它(并将 eval 放回)它打印两个列表,['1']和 []。有谁知道为什么它在 3.3 中不起作用或者我如何让它在 3.3 中起作用?提前致谢。