《How to Think Like a Computer Scientist: Interactive Edition》 這網站提供互動式的Python教學,對於想要自學的程式語言的人可以試試看。總共分成19個章節:
- General Introduction:簡介
- Simple Python Data:基本的資料型態
- Debugging Interlude 1:程式錯誤與除錯介紹
《How to Think Like a Computer Scientist: Interactive Edition》 這網站提供互動式的Python教學,對於想要自學的程式語言的人可以試試看。總共分成19個章節:
SyntaxError: Non-ASCII character '\xe8' in file 05.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details這是因為註解裡面包含中文,但確定此script是用UTF-8儲存的。參考了《PEP 263 -- Defining Python Source Code Encodings》一文,了解在程式最前面,#!/usr/bin/env 這一行後面要宣告這個script是以哪種編碼方式儲存,如下:
![]() |
| Envelope proteins of Zika virus (PDB code: 5IRE) |
#!/usr/bin/python
def one2three(a):
"""
Convert one letter code to three letter code
"""
aa1to3 = {'A':"Ala", 'R':"Arg", 'N':"Asn", 'D':"Asp", 'C':"Cys",
'E':"Glu", 'Q':"Gln", 'G':"Gly", 'H':"His", 'I':"Ile",
'L':"Leu", 'K':"Lys", 'M':"Met", 'F':"Phe", 'P':"Pro",
'S':"Ser", 'T':"Thr", 'W':"Trp", 'Y':"Tyr", 'V':"Val"}
aa3to1 = {three: one for one, three in aa1to3.iteritems()}
if (a in aa1to3.iterkeys()):
aaa = aa1to3[a]
else:
aaa = 'X'
return aaa
if __name__ == "__main__":
s = str(raw_input("Please enter a protein sequence: "))
seq = list()
for a in s.upper():
seq.append(one2three(a))
print('-'.join(seq))