python基础练习题-190114

练习(二)计算以下序列的GC含量(知识点:float、count):ATTCTTTCTTCCAAACCTCTTCAATTATATCTGTTTAATTCCCTCTTTCTTTGTCTGAAAACAATTAATA

#python
>>> x='ATTCTTTCTTCCAAACCTCTTCAATTATATCTGTTTAATTCCCTCTTTCTTTGTCTGAAAACAATTAATA'

>>> g=x.count('G')

>>> c=x.count('C')

>>> length=len(x)

>>> percent=float(g+c)/length

>>> percent

0.2676056338028169

练习(三)计算1~100(含100)所有偶数的和,脚本保存为sum.py(知识点:循环语句、判断语

句)


vim sum.py

n=1

sum=0

while n <= 100:

        n = n+1

        if n%2 == 0:

                sum = sum+n

print(sum)

练习(四)获得以下序列的反向互补序列,并保存为reverse_complement.py文件(知识点:循环

语句、判断语句或字典):ATTCTTTCTTCCAAACCNTCTTCAATTATATCTGTTTAATTCCCTCTTTCTTTGTCTGAAAACAATTAATA

vim reverse_complement.py

seq = 'ATTCTTTCTTCCAAACCNTCTTCAATTATATCTGTTTAATTCCCTCTTTCTTTGTCTGAAAACAATTAATA'

reverse_seq =''

dict = {'A':'T','T':'A','C':'G','G':'C','N':'N'}

for i in seq:

        reverse_seq =dict[i] + reverse_seq

print(reverse_seq)

你可能感兴趣的:(python基础练习题-190114)