我正在編寫一個程序,在該程序中我可以反轉序列並全部替換爲Ts,所有Cs都帶有Gs,所有帶有Cs的Gs以及所有Ts都帶有As。該程序將讀取一系列鹼基並輸出反向互補序列。我無法做到這一點所以任何人都請爲我的代碼來看看幫助我:Python結構錯誤
word = raw_input("Enter sequence: ")
a = word.replace('A', 'T')
b = word.replace('C', 'G')
c = word.replace('G', 'C')
d = word.replace('T', 'A')
if a == word and b == word and c == word and d == word:
print "Reverse complement sequence: ", word
而且我想這種輸出:
Enter sequence: CGGTGATGCAAGG
Reverse complement sequence: CCTTGCATCACCG
問候
在您的代碼中,此錯誤即將出現! :追溯(最近一次調用最後一次): 文件「C:\ Python26 \ python code \ week 4 \ Q9」,第3行,在 newword =''.join(swap_dict [letter] ) 文件「C:\ Python26 \ python code \ week 4 \ Q9」,第3行,在 newword =''.join(swap_dict [字母]爲反向(字)字母) KeyError:'S' –
jaddy123
啊。 'KeyError'說S不在交換字典中,所以它不知道如何處理它。你想在字母S上發生什麼? – DSM